randmarcomps 1.482.0 → 1.484.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.
@@ -67183,67 +67183,68 @@ function ProductInventoryButton({
67183
67183
  applicationId: e,
67184
67184
  randmarSku: t,
67185
67185
  inventory: n,
67186
- buttonSize: o = "default"
67186
+ buttonSize: o = "default",
67187
+ buttonClassName: l
67187
67188
  }) {
67188
- var Ve;
67189
- const l = useRef(null), d = useIntersectionObserver({
67190
- elementRef: l,
67189
+ var Ne;
67190
+ const d = useRef(null), f = useIntersectionObserver({
67191
+ elementRef: d,
67191
67192
  threshold: 0.1,
67192
67193
  rootMargin: "100px",
67193
67194
  freezeOnceVisible: !0
67194
- }), { toast: f } = useToast(), [g, b] = useState(!1), [S, _] = useState(!1), [C, E] = useState(!1), {
67195
- data: R,
67196
- isLoading: A,
67197
- isFetching: M
67195
+ }), { toast: g } = useToast(), [b, S] = useState(!1), [_, C] = useState(!1), [E, R] = useState(!1), {
67196
+ data: A,
67197
+ isLoading: M,
67198
+ isFetching: I
67198
67199
  } = useGetV4PartnerByApplicationIdAccountQuery({
67199
67200
  applicationId: e
67200
67201
  }, {
67201
- skip: !e || !d
67202
+ skip: !e || !f
67202
67203
  }), {
67203
- data: I,
67204
- isLoading: V,
67205
- isFetching: q
67204
+ data: V,
67205
+ isLoading: q,
67206
+ isFetching: Q
67206
67207
  } = useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({
67207
67208
  routeApplicationId: e,
67208
67209
  randmarSku: t,
67209
67210
  withSpecification: !1
67210
67211
  }, {
67211
- skip: !!n || !d
67212
- }), [Q] = usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(), te = n ?? ((Ve = I == null ? void 0 : I.Distribution) == null ? void 0 : Ve.Inventory);
67212
+ skip: !!n || !f
67213
+ }), [te] = usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(), j = n ?? ((Ne = V == null ? void 0 : V.Distribution) == null ? void 0 : Ne.Inventory);
67213
67214
  useEffect(() => {
67214
- b(!1);
67215
+ S(!1);
67215
67216
  }, [t]);
67216
- const { inventoryQuantity: j, totalIncomingQuantity: F } = useMemo(() => {
67217
- if (!te || te.length === 0)
67217
+ const { inventoryQuantity: F, totalIncomingQuantity: ne } = useMemo(() => {
67218
+ if (!j || j.length === 0)
67218
67219
  return { inventoryQuantity: 0, totalIncomingQuantity: 0 };
67219
- const Ne = te.reduce((Oe, Ae) => Oe + (Ae.AvailableQuantity || 0), 0), oe = te.reduce((Oe, Ae) => Oe + (Ae.PurchaseOrderQuantity || 0), 0);
67220
- return { inventoryQuantity: Ne, totalIncomingQuantity: oe };
67221
- }, [te]);
67222
- if (A || M || V || q)
67223
- return /* @__PURE__ */ jsx("div", { ref: l, children: /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-36 rounded-md" }) });
67224
- const ae = () => {
67225
- C || !(R != null && R.IsReseller) || (E(!0), Q({
67220
+ const oe = j.reduce((Ae, $e) => Ae + ($e.AvailableQuantity || 0), 0), Oe = j.reduce((Ae, $e) => Ae + ($e.PurchaseOrderQuantity || 0), 0);
67221
+ return { inventoryQuantity: oe, totalIncomingQuantity: Oe };
67222
+ }, [j]);
67223
+ if (M || I || q || Q)
67224
+ return /* @__PURE__ */ jsx("div", { ref: d, children: /* @__PURE__ */ jsx(Skeleton, { className: cn("h-10 w-36 rounded-md", l) }) });
67225
+ const se = () => {
67226
+ E || !(A != null && A.IsReseller) || (R(!0), te({
67226
67227
  routeResellerId: e ?? "",
67227
67228
  randmarSku: t ?? ""
67228
- }).then((Ne) => {
67229
- Ne.error || Ne.data === !1 ? f({ title: "Warning", description: "Reorder is pending or requires manual approval. Contact the Randmar team for details.", variant: "warning" }) : f({ title: "Success", description: "Qualification successfully submitted.", variant: "success" }), _(!1);
67230
- }).catch((Ne) => {
67231
- console.error(Ne), f({ title: "Error", description: "Error submitting your qualification.", variant: "destructive" });
67229
+ }).then((oe) => {
67230
+ oe.error || oe.data === !1 ? g({ title: "Warning", description: "Reorder is pending or requires manual approval. Contact the Randmar team for details.", variant: "warning" }) : g({ title: "Success", description: "Qualification successfully submitted.", variant: "success" }), C(!1);
67231
+ }).catch((oe) => {
67232
+ console.error(oe), g({ title: "Error", description: "Error submitting your qualification.", variant: "destructive" });
67232
67233
  }).finally(() => {
67233
- E(!1);
67234
+ R(!1);
67234
67235
  }));
67235
67236
  };
67236
- if (!te)
67237
- return /* @__PURE__ */ jsx("div", { ref: l, children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip$1, { children: [
67238
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx("span", { tabIndex: 0, children: /* @__PURE__ */ jsxs(Button$1, { disabled: !0, size: o, variant: "outline", className: "text-sm", children: [
67237
+ if (!j)
67238
+ return /* @__PURE__ */ jsx("div", { ref: d, children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip$1, { children: [
67239
+ /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx("span", { tabIndex: 0, children: /* @__PURE__ */ jsxs(Button$1, { disabled: !0, size: o, variant: "outline", className: cn("text-sm", l), children: [
67239
67240
  /* @__PURE__ */ jsx(Warehouse, { size: "16", className: "mr-2" }),
67240
67241
  "No data"
67241
67242
  ] }) }) }),
67242
67243
  /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "No inventory data could be found for this product." }) })
67243
67244
  ] }) }) });
67244
- if (R != null && R.IsReseller && j <= 0 && F <= 0)
67245
- return /* @__PURE__ */ jsx("div", { ref: l, children: /* @__PURE__ */ jsxs(Dialog, { open: S, onOpenChange: _, children: [
67246
- /* @__PURE__ */ jsx(DialogTrigger, { asChild: !0, children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", size: o, className: "text-sm reseller-theme text-primary", children: [
67245
+ if (A != null && A.IsReseller && F <= 0 && ne <= 0)
67246
+ return /* @__PURE__ */ jsx("div", { ref: d, children: /* @__PURE__ */ jsxs(Dialog, { open: _, onOpenChange: C, children: [
67247
+ /* @__PURE__ */ jsx(DialogTrigger, { asChild: !0, children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", size: o, className: cn("text-sm reseller-theme text-primary", l), children: [
67247
67248
  /* @__PURE__ */ jsx(Warehouse, { size: "16", className: "mr-2" }),
67248
67249
  "Request to stock"
67249
67250
  ] }) }),
@@ -67251,29 +67252,33 @@ function ProductInventoryButton({
67251
67252
  /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: "Request to stock" }) }),
67252
67253
  /* @__PURE__ */ jsx("p", { className: "py-4", children: "Are you sure you want to request this product to be stocked?" }),
67253
67254
  /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
67254
- /* @__PURE__ */ jsx(Button$1, { variant: "outline", onClick: () => _(!1), disabled: C, children: "Cancel" }),
67255
- /* @__PURE__ */ jsx(Button$1, { onClick: ae, disabled: C, children: C ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67255
+ /* @__PURE__ */ jsx(Button$1, { variant: "outline", onClick: () => C(!1), disabled: E, children: "Cancel" }),
67256
+ /* @__PURE__ */ jsx(Button$1, { onClick: se, disabled: E, children: E ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67256
67257
  /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin mr-2" }),
67257
67258
  "Requesting..."
67258
67259
  ] }) : "Confirm" })
67259
67260
  ] })
67260
67261
  ] })
67261
67262
  ] }) });
67262
- const se = j <= 0 && F > 0;
67263
- return /* @__PURE__ */ jsx("div", { ref: l, children: /* @__PURE__ */ jsxs(Dialog, { open: g, onOpenChange: b, children: [
67263
+ const Ve = F <= 0 && ne > 0;
67264
+ return /* @__PURE__ */ jsx("div", { ref: d, children: /* @__PURE__ */ jsxs(Dialog, { open: b, onOpenChange: S, children: [
67264
67265
  /* @__PURE__ */ jsx(DialogTrigger, { asChild: !0, children: /* @__PURE__ */ jsxs(
67265
67266
  Button$1,
67266
67267
  {
67267
67268
  variant: "outline",
67268
67269
  size: o,
67269
- className: `text-sm ${se ? "manufacturer-theme text-primary" : j > 0 ? "text-green-700" : "text-red-700"}`,
67270
+ className: cn(
67271
+ "text-sm",
67272
+ Ve ? "manufacturer-theme text-primary" : F > 0 ? "text-green-700" : "text-red-700",
67273
+ l
67274
+ ),
67270
67275
  children: [
67271
67276
  /* @__PURE__ */ jsx(Warehouse, { size: "16", className: "mr-2" }),
67272
- se ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67273
- formatNumber(F),
67277
+ Ve ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67278
+ formatNumber(ne),
67274
67279
  " Incoming"
67275
- ] }) : j > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67276
- formatNumber(j),
67280
+ ] }) : F > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
67281
+ formatNumber(F),
67277
67282
  " in stock"
67278
67283
  ] }) : /* @__PURE__ */ jsx(Fragment$1, { children: "Out of stock" })
67279
67284
  ]
@@ -67284,7 +67289,7 @@ function ProductInventoryButton({
67284
67289
  /* @__PURE__ */ jsx(Warehouse, { className: "mr-2", size: 18 }),
67285
67290
  "Inventory Information"
67286
67291
  ] }) }),
67287
- /* @__PURE__ */ jsx(ProductInventoryGrid, { inventory: te })
67292
+ /* @__PURE__ */ jsx(ProductInventoryGrid, { inventory: j })
67288
67293
  ] })
67289
67294
  ] }) });
67290
67295
  }
@@ -76819,30 +76824,38 @@ function ProductCard({
76819
76824
  `product_image_${t.RandmarSKU}`
76820
76825
  ) })
76821
76826
  ] }),
76822
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col @[36rem]:flex-row gap-6 mt-4", children: [
76823
- /* @__PURE__ */ jsxs("div", { className: "flex flex-row @[36rem]:flex-col gap-4 justify-center @[36rem]:justify-start @[36rem]:order-2 order-1", children: [
76824
- n && /* @__PURE__ */ jsx(Link, { to: n, children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", className: "h-11 px-4 text-sm font-medium justify-start", children: [
76825
- /* @__PURE__ */ jsx(Eye, { className: "mr-2" }),
76826
- "View Product"
76827
- ] }) }),
76828
- /* @__PURE__ */ jsx(
76829
- ProductInventoryButton,
76830
- {
76831
- applicationId: e ?? "",
76832
- randmarSku: t.RandmarSKU ?? "",
76833
- inventory: (Mt = t.Distribution) == null ? void 0 : Mt.Inventory
76834
- }
76835
- )
76836
- ] }),
76837
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 @[36rem]:order-1 order-2", children: Je && t.Distribution && /* @__PURE__ */ jsxs("div", { className: "w-full", children: [
76838
- /* @__PURE__ */ jsx("div", { className: "flex items-center", children: "You have " + rt.length + (rt.length > 1 ? " opportunities" : " opportunity") + " for this product:" }),
76839
- /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx("div", { className: "space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1", children: rt.map(
76840
- (Ze, ct) => Le(Ze) ? /* @__PURE__ */ jsxs("div", { className: `flex justify-between items-center rounded-lg transition-colors py-2 px-4 border border-muted cursor-pointer ${Ze.BidNumber == (E == null ? void 0 : E.BidNumber) ? "bg-purple-100 border-2 border-purple-900" : "bg-white border-1 border-purple-600 hover:bg-purple-200"}`, onClick: () => {
76841
- R(Ze.BidNumber !== (E == null ? void 0 : E.BidNumber) ? Ze : null);
76827
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col @[36rem]:flex-row gap-6 mt-4", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 @[36rem]:order-1 order-2", children: Je && t.Distribution && /* @__PURE__ */ jsxs("div", { className: "w-full", children: [
76828
+ /* @__PURE__ */ jsx("div", { className: "flex items-center", children: "You have " + rt.length + (rt.length > 1 ? " opportunities" : " opportunity") + " for this product:" }),
76829
+ /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx("div", { className: "space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1", children: rt.map(
76830
+ (Ze, ct) => Le(Ze) ? /* @__PURE__ */ jsxs("div", { className: `flex justify-between items-center rounded-lg transition-colors py-2 px-4 border border-muted cursor-pointer ${Ze.BidNumber == (E == null ? void 0 : E.BidNumber) ? "bg-purple-100 border-2 border-purple-900" : "bg-white border-1 border-purple-600 hover:bg-purple-200"}`, onClick: () => {
76831
+ R(Ze.BidNumber !== (E == null ? void 0 : E.BidNumber) ? Ze : null);
76832
+ }, children: [
76833
+ /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
76834
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-sm", children: Ze.Opportunity }),
76835
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-neutral-900", children: Ze.BidNumber })
76836
+ ] }) }),
76837
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
76838
+ /* @__PURE__ */ jsx("span", { className: "font-semibold", children: formatMoney(Ze.Price ?? 0) }),
76839
+ Ze.Rebate && Ze.Rebate > 0 && /* @__PURE__ */ jsxs("span", { className: "text-xs text-green-600", children: [
76840
+ "Rebate: ",
76841
+ formatMoney(Ze.Rebate)
76842
+ ] }),
76843
+ Ze.EndDate && /* @__PURE__ */ jsxs("span", { className: "text-xs text-neutral-600", children: [
76844
+ "Ends: ",
76845
+ ot(Ze.EndDate)
76846
+ ] })
76847
+ ] })
76848
+ ] }, ct) : /* @__PURE__ */ jsxs(Tooltip$1, { children: [
76849
+ /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-purple-100 border border-muted cursor-pointer !bg-neutral-50 hover:bg-neutral-100", onClick: () => {
76850
+ Ze.BidNumber && b(`/${e}/Opportunity/${Ze.ManufacturerId}/${Ze.BidNumber}`);
76842
76851
  }, children: [
76843
76852
  /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
76844
76853
  /* @__PURE__ */ jsx("span", { className: "font-medium text-sm", children: Ze.Opportunity }),
76845
- /* @__PURE__ */ jsx("span", { className: "text-xs text-neutral-900", children: Ze.BidNumber })
76854
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-neutral-900", children: [
76855
+ Ze.BidNumber,
76856
+ " ",
76857
+ /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs mx-1 h-5 bg-gray-100", children: "Currently unavailable" })
76858
+ ] })
76846
76859
  ] }) }),
76847
76860
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
76848
76861
  /* @__PURE__ */ jsx("span", { className: "font-semibold", children: formatMoney(Ze.Price ?? 0) }),
@@ -76855,43 +76868,19 @@ function ProductCard({
76855
76868
  ot(Ze.EndDate)
76856
76869
  ] })
76857
76870
  ] })
76858
- ] }, ct) : /* @__PURE__ */ jsxs(Tooltip$1, { children: [
76859
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-purple-100 border border-muted cursor-pointer !bg-neutral-50 hover:bg-neutral-100", onClick: () => {
76860
- Ze.BidNumber && b(`/${e}/Opportunity/${Ze.ManufacturerId}/${Ze.BidNumber}`);
76861
- }, children: [
76862
- /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
76863
- /* @__PURE__ */ jsx("span", { className: "font-medium text-sm", children: Ze.Opportunity }),
76864
- /* @__PURE__ */ jsxs("span", { className: "text-xs text-neutral-900", children: [
76865
- Ze.BidNumber,
76866
- " ",
76867
- /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs mx-1 h-5 bg-gray-100", children: "Currently unavailable" })
76868
- ] })
76869
- ] }) }),
76870
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end", children: [
76871
- /* @__PURE__ */ jsx("span", { className: "font-semibold", children: formatMoney(Ze.Price ?? 0) }),
76872
- Ze.Rebate && Ze.Rebate > 0 && /* @__PURE__ */ jsxs("span", { className: "text-xs text-green-600", children: [
76873
- "Rebate: ",
76874
- formatMoney(Ze.Rebate)
76875
- ] }),
76876
- Ze.EndDate && /* @__PURE__ */ jsxs("span", { className: "text-xs text-neutral-600", children: [
76877
- "Ends: ",
76878
- ot(Ze.EndDate)
76879
- ] })
76880
- ] })
76881
- ] }) }),
76882
- /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "View Opportunity" }) })
76883
- ] }, ct)
76884
- ) }) })
76885
- ] }) })
76886
- ] }),
76887
- /* @__PURE__ */ jsxs("div", { className: "flex flex-row flex-wrap justify-between items-end mt-4 gap-4", children: [
76888
- /* @__PURE__ */ jsxs("div", { className: "flex-shrink-1 flex flex-col gap-3", children: [
76889
- t.Distribution && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: oe > 0 ? /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs("span", { className: "text-2xl font-bold whitespace-nowrap", children: [
76871
+ ] }) }),
76872
+ /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "View Opportunity" }) })
76873
+ ] }, ct)
76874
+ ) }) })
76875
+ ] }) }) }),
76876
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex flex-col gap-4", children: [
76877
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-row flex-wrap justify-between items-end gap-4", children: [
76878
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3 flex-1", children: t.Distribution && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: oe > 0 ? /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs("span", { className: "text-2xl font-bold whitespace-nowrap", children: [
76890
76879
  "Cost: ",
76891
76880
  formatMoney(oe)
76892
76881
  ] }) }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
76893
76882
  /* @__PURE__ */ jsxs("div", { className: "flex items-center flex-wrap", children: [
76894
- Oe > 0 && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("span", { className: "text-2xl font-bold whitespace-nowrap", children: formatMoney((E ? (Ke = (Rt = t.Opportunities) == null ? void 0 : Rt.find((Ze) => Ze.BidNumber == E.BidNumber)) == null ? void 0 : Ke.Price : Ae) ?? 0) }) }),
76883
+ Oe > 0 && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("span", { className: "text-2xl font-bold whitespace-nowrap", children: formatMoney((E ? (Rt = (Mt = t.Opportunities) == null ? void 0 : Mt.find((Ze) => Ze.BidNumber == E.BidNumber)) == null ? void 0 : Rt.Price : Ae) ?? 0) }) }),
76895
76884
  A > 0 && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground line-through ml-2 whitespace-nowrap", children: formatMoney(Oe) })
76896
76885
  ] }),
76897
76886
  A > 0 && /* @__PURE__ */ jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxs(Badge, { variant: "outline", className: "bg-red-50 text-red-700 rounded-full px-3 whitespace-nowrap", children: [
@@ -76899,7 +76888,7 @@ function ProductCard({
76899
76888
  A,
76900
76889
  "% OFF"
76901
76890
  ] }),
76902
- ((Ye = t.InstantRebate) == null ? void 0 : Ye.EndDate) && /* @__PURE__ */ jsxs(Fragment$1, { children: [
76891
+ ((Ke = t.InstantRebate) == null ? void 0 : Ke.EndDate) && /* @__PURE__ */ jsxs(Fragment$1, { children: [
76903
76892
  /* @__PURE__ */ jsx("span", { className: "mx-1.5", children: "●" }),
76904
76893
  " Ends ",
76905
76894
  t.InstantRebate.EndDate.split("T")[0]
@@ -76910,13 +76899,85 @@ function ProductCard({
76910
76899
  E.EndDate.split("T")[0]
76911
76900
  ] })
76912
76901
  ] }) })
76913
- ] }) }),
76914
- /* @__PURE__ */ jsxs(
76902
+ ] }) }) }),
76903
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full @[36rem]:w-auto", children: [
76904
+ f && /* @__PURE__ */ jsx(
76905
+ Button$1,
76906
+ {
76907
+ className: "gap-2 whitespace-nowrap bg-green-600 hover:bg-green-700",
76908
+ onClick: Ge,
76909
+ disabled: I,
76910
+ children: I ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
76911
+ /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
76912
+ "Syncing..."
76913
+ ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
76914
+ /* @__PURE__ */ jsx(ShoppingCart, { className: "mr-2" }),
76915
+ "Sync to Shopify"
76916
+ ] })
76917
+ }
76918
+ ),
76919
+ g,
76920
+ typeof l < "u" && /* @__PURE__ */ jsxs("div", { className: "flex gap-2 whitespace-nowrap", children: [
76921
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center border rounded-md", children: [
76922
+ /* @__PURE__ */ jsx(
76923
+ Button$1,
76924
+ {
76925
+ variant: "ghost",
76926
+ size: "icon",
76927
+ className: "rounded-r-none",
76928
+ onClick: st,
76929
+ disabled: typeof _ < "u" && (_ <= 1 || !t.AvailableToBuy || d),
76930
+ children: "-"
76931
+ }
76932
+ ),
76933
+ /* @__PURE__ */ jsx(
76934
+ "input",
76935
+ {
76936
+ value: _,
76937
+ onChange: at,
76938
+ onBlur: tt,
76939
+ onClick: (Ze) => Ze.currentTarget.select(),
76940
+ className: `w-6 @[36rem]:w-12 text-center border-0 focus:ring-0 focus:outline-none ${!t.AvailableToBuy || d ? "text-gray-400" : ""}`,
76941
+ disabled: !t.AvailableToBuy || d
76942
+ }
76943
+ ),
76944
+ /* @__PURE__ */ jsx(
76945
+ Button$1,
76946
+ {
76947
+ variant: "ghost",
76948
+ size: "icon",
76949
+ className: "rounded-l-none",
76950
+ onClick: et,
76951
+ disabled: !t.AvailableToBuy || d,
76952
+ children: "+"
76953
+ }
76954
+ )
76955
+ ] }),
76956
+ /* @__PURE__ */ jsx(
76957
+ Button$1,
76958
+ {
76959
+ className: "gap-2 whitespace-nowrap",
76960
+ onClick: lt,
76961
+ disabled: !t.AvailableToBuy || d,
76962
+ children: d ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
76963
+ /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
76964
+ "Adding..."
76965
+ ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
76966
+ /* @__PURE__ */ jsx(ShoppingCart, { className: "mr-2" }),
76967
+ "Add to Cart"
76968
+ ] })
76969
+ }
76970
+ )
76971
+ ] })
76972
+ ] })
76973
+ ] }),
76974
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2 @[36rem]:flex-row", children: [
76975
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-[10rem]", children: /* @__PURE__ */ jsxs(
76915
76976
  Button$1,
76916
76977
  {
76917
76978
  variant: "outline",
76918
76979
  type: "button",
76919
- className: "h-11 px-4 text-sm font-medium justify-start w-fit",
76980
+ className: "h-11 px-4 text-sm font-medium justify-start w-full",
76920
76981
  onClick: () => te(!0),
76921
76982
  disabled: !$e,
76922
76983
  children: [
@@ -76924,77 +76985,21 @@ function ProductCard({
76924
76985
  "View statistics"
76925
76986
  ]
76926
76987
  }
76927
- )
76928
- ] }),
76929
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full", children: [
76930
- f && /* @__PURE__ */ jsx(
76931
- Button$1,
76988
+ ) }),
76989
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-[10rem]", children: /* @__PURE__ */ jsx(
76990
+ ProductInventoryButton,
76932
76991
  {
76933
- className: "gap-2 whitespace-nowrap bg-green-600 hover:bg-green-700",
76934
- onClick: Ge,
76935
- disabled: I,
76936
- children: I ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
76937
- /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
76938
- "Syncing..."
76939
- ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
76940
- /* @__PURE__ */ jsx(ShoppingCart, { className: "mr-2" }),
76941
- "Sync to Shopify"
76942
- ] })
76992
+ applicationId: e ?? "",
76993
+ randmarSku: t.RandmarSKU ?? "",
76994
+ inventory: (Ye = t.Distribution) == null ? void 0 : Ye.Inventory,
76995
+ buttonSize: "lg",
76996
+ buttonClassName: "w-full h-11 justify-start"
76943
76997
  }
76944
- ),
76945
- g,
76946
- typeof l < "u" && /* @__PURE__ */ jsxs("div", { className: "flex gap-2 whitespace-nowrap", children: [
76947
- /* @__PURE__ */ jsxs("div", { className: "flex items-center border rounded-md", children: [
76948
- /* @__PURE__ */ jsx(
76949
- Button$1,
76950
- {
76951
- variant: "ghost",
76952
- size: "icon",
76953
- className: "rounded-r-none",
76954
- onClick: st,
76955
- disabled: typeof _ < "u" && (_ <= 1 || !t.AvailableToBuy || d),
76956
- children: "-"
76957
- }
76958
- ),
76959
- /* @__PURE__ */ jsx(
76960
- "input",
76961
- {
76962
- value: _,
76963
- onChange: at,
76964
- onBlur: tt,
76965
- onClick: (Ze) => Ze.currentTarget.select(),
76966
- className: `w-6 @[36rem]:w-12 text-center border-0 focus:ring-0 focus:outline-none ${!t.AvailableToBuy || d ? "text-gray-400" : ""}`,
76967
- disabled: !t.AvailableToBuy || d
76968
- }
76969
- ),
76970
- /* @__PURE__ */ jsx(
76971
- Button$1,
76972
- {
76973
- variant: "ghost",
76974
- size: "icon",
76975
- className: "rounded-l-none",
76976
- onClick: et,
76977
- disabled: !t.AvailableToBuy || d,
76978
- children: "+"
76979
- }
76980
- )
76981
- ] }),
76982
- /* @__PURE__ */ jsx(
76983
- Button$1,
76984
- {
76985
- className: "gap-2 whitespace-nowrap",
76986
- onClick: lt,
76987
- disabled: !t.AvailableToBuy || d,
76988
- children: d ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
76989
- /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
76990
- "Adding..."
76991
- ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
76992
- /* @__PURE__ */ jsx(ShoppingCart, { className: "mr-2" }),
76993
- "Add to Cart"
76994
- ] })
76995
- }
76996
- )
76997
- ] })
76998
+ ) }),
76999
+ n && /* @__PURE__ */ jsx(Link, { to: n, className: "flex-1 min-w-[10rem]", children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", className: "h-11 px-4 text-sm font-medium justify-start w-full", children: [
77000
+ /* @__PURE__ */ jsx(Eye, { className: "mr-2" }),
77001
+ "View Product"
77002
+ ] }) })
76998
77003
  ] })
76999
77004
  ] })
77000
77005
  ] }) }),
@@ -1194,7 +1194,7 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
1194
1194
 
1195
1195
  Defaulting to \`null\`.`}var Root$2=Progress$1,Indicator=ProgressIndicator;const Progress=React__namespace.forwardRef(({className:e,value:t,...n},o)=>jsxRuntime.jsx(Root$2,{ref:o,className:cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",e),...n,children:jsxRuntime.jsx(Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})}));Progress.displayName=Root$2.displayName;function ManufacturerInventoryFinanceCard({manufacturer:e,isLoading:t}){const{data:n,isLoading:o,isFetching:l}=useGetV4ManufacturerByRouteManufacturerIdInventoryValueQuery({routeManufacturerId:(e==null?void 0:e.ManufacturerId)??""},{skip:!(e!=null&&e.ManufacturerId)}),d=(e==null?void 0:e.DefaultMaxInventoryValue)??0,f=(n||[]).reduce((_,S)=>_+(S.InventoryValue||0),0),g=d-f,b=Math.round(f/d*100);return t||o||l?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(DollarSign,{className:"h-5 w-5 text-muted-foreground"}),"Inventory Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current inventory financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[d!==0&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Max Allowance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(d)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Current value"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(f)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available"}),jsxRuntime.jsx("span",{className:`font-bold ${g>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(g)})]})]}),d!==0&&jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Budget Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[b,"%"]}),b>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:b>80?"High usage alert":"Budget usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:b,className:"h-2"})]})]})]})}function ManufacturerCreditFinanceCard({manufacturer:e,isLoading:t}){const n=(e==null?void 0:e.CreditLimit)??0,o=(e==null?void 0:e.OutstandingBalance)??0,l=n-o,d=Math.round(o/n*100);return t?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(CreditCard,{className:"h-5 w-5 text-muted-foreground"}),"Credit Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current credit financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Limit"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(n)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Outstanding Balance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(o)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available Credit"}),jsxRuntime.jsx("span",{className:`font-bold ${l>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(l)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[d,"%"]}),d>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:d>80?"High credit usage alert":"Credit usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:d,className:"h-2"})]})]})]})}function SalesChartCard({statistics:e,loading:t=!1,mode:n="month",chartHeight:o=300,className:l,size:d="default"}){return t?jsxRuntime.jsxs(Card,{className:cn("w-full",l),children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-48 rounded-md"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsx("div",{style:{height:o},children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full rounded-md"})}),d==="default"&&n==="month"&&jsxRuntime.jsxs("div",{className:"mt-4 flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-10 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-40 rounded-md"})]})]})]}):jsxRuntime.jsxs(Card,{className:cn("w-full",l),children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:n==="week"?"Weekly Sales Performance":"Monthly Sales Performance"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(SalesChart,{statistics:e,mode:n,chartHeight:o,size:d})})]})}function ManufacturerOverviewPage({applicationId:e,readonly:t,withReports:n,manufacturer:o,userEmail:l}){const{data:d,isLoading:f,isError:g}=useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:e,withSpecification:!0},{skip:!!o}),[b,_]=React.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),S=React.useCallback(()=>t?!1:b.publicInfo.hasUnsavedChanges||b.qualifications.hasUnsavedChanges||b.billingInfo.hasUnsavedChanges,[t,b]),R=React.useCallback((A,M)=>{_(I=>{var j;return((j=I[A])==null?void 0:j.hasUnsavedChanges)!==M.hasUnsavedChanges?(console.log(`Updating form state for ${A}:`,M.hasUnsavedChanges),{...I,[A]:M}):I})},[]),{NavigationGuardDialog:C}=useRouterNavigationGuard(S),E=o??d;return jsxRuntime.jsxs("div",{className:"@container",children:[g?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your manufacturer information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:E==null?void 0:E.FiscalYearMonthStart,salesData:E==null?void 0:E.SalesData,isLoading:f}),jsxRuntime.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChartCard,{statistics:(E==null?void 0:E.SalesStatistics)??[],loading:f}),jsxRuntime.jsx(ManufacturerResellerOrdersSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",activeOrders:(E==null?void 0:E.ActiveOrderDetails)??void 0,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerInventoryFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerCreditFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerReorderingCard,{manufacturer:E??{},onSave:()=>{},loading:f,readonly:t}),n&&jsxRuntime.jsx(ManufacturerPublicInfoSection,{manufacturer:E,readonly:t,isLoading:f,onUnsavedChanges:A=>R("publicInfo",{hasUnsavedChanges:A})}),n&&jsxRuntime.jsx(OpenToWorkSection,{manufacturer:E,readonly:t,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerBillingInfoSection,{manufacturer:E,readonly:t,isLoading:f,onUnsavedChanges:A=>R("billingInfo",{hasUnsavedChanges:A})}),n&&jsxRuntime.jsx(ManufacturerQualificationsSection,{manufacturer:E,readonly:t,isLoading:f,onUnsavedChanges:A=>R("qualifications",{hasUnsavedChanges:A})})]}),n&&jsxRuntime.jsx(ManufacturerReportsSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",userEmail:l,isLoading:f})]}),jsxRuntime.jsx(C,{})]})}function ManufacturerCategories({categories:e,activeCategory:t,onSelectCategory:n}){return jsxRuntime.jsx("div",{className:"grid",children:jsxRuntime.jsx("div",{className:"flex overflow-x-auto small-scrollbar pb-4",children:jsxRuntime.jsxs("div",{className:"flex gap-2 items-baseline",children:[jsxRuntime.jsx("p",{children:"Category filter:"}),e.map(o=>jsxRuntime.jsxs(Button$1,{onClick:()=>n(o.CategoryCode??""),variant:t===o.CategoryCode?"default":"outline",size:"sm",className:"px-3 py-1.5 text-xs whitespace-nowrap rounded-full",children:[o.CategoryName??"Undefined",o.QualificationRequired&&jsxRuntime.jsx(ShieldCheck,{className:`ml-1 w-5 h-5 ${t!==o.CategoryCode?"text-red-500":""}`})]},o.CategoryCode))]})})})}function CategoryStats(e){const{data:t,isLoading:n,isFetching:o}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:e.appID,manufacturerId:e.manufID,categoryCode:e.categoryCode});return jsxRuntime.jsx(Card,{className:"w-full",children:jsxRuntime.jsx(CardContent,{className:"p-4 space-y-1",children:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:e.categoryName}),jsxRuntime.jsx(SalesChart,{statistics:(t==null?void 0:t.SalesStatistics)??[],loading:n||o,chartHeight:300})]})})})}function ManufacturerCategoriesStats(e){return(e.categories??[]).filter(n=>n.CategoryName).map(n=>jsxRuntime.jsx(CategoryStats,{appID:e.appID,manufID:e.manufID,categoryCode:n.CategoryCode,categoryName:n.CategoryName},`${e.manufID}-${n.CategoryCode}`))}const badgeVariants=cva("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground border border-input hover:bg-accent hover:text-accent-foreground",success:"bg-green-600 text-white hover:bg-green-700",warning:"bg-yellow-500 text-white hover:bg-yellow-600",info:"bg-blue-500 text-white hover:bg-blue-600",ghost:"bg-background hover:bg-accent hover:text-accent-foreground",randmarRed:"bg-randmar-red text-white hover:bg-randmar-red/80",randmarBlue:"bg-randmar-blue text-white hover:bg-randmar-blue/80",randmarPurple:"bg-randmar-purple text-white hover:bg-randmar-purple/80",randmarGreen:"bg-randmar-green text-black hover:bg-randmar-green/80",randmarBlack:"bg-randmar-black text-white hover:bg-randmar-black/80",randmarYellow:"bg-randmar-yellow text-black hover:bg-randmar-yellow/80"},size:{default:"h-6",sm:"h-5 text-[10px]",lg:"h-7 px-3"}},defaultVariants:{variant:"default",size:"default"}}),Badge=React__namespace.forwardRef(({className:e,variant:t,size:n,icon:o,children:l,...d},f)=>jsxRuntime.jsxs("div",{ref:f,className:cn(badgeVariants({variant:t,size:n}),e),...d,children:[o&&jsxRuntime.jsx("span",{className:"mr-1",children:o}),l]}));Badge.displayName="Badge";function ManufacturerCategorySummary({name:e="N/A",niche:t="N/A",productsNumber:n=0,autoreorder:o=!1,starred:l=!1,isLoading:d=!1,children:f}){return d?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{className:"pb-4",children:jsxRuntime.jsxs("div",{className:"flex items-start justify-between",children:[jsxRuntime.jsx("div",{className:"space-y-1 flex-1",children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("div",{className:"h-3 w-28 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsx("div",{className:"h-5 w-48 bg-muted rounded-md animate-pulse"})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-1",children:[jsxRuntime.jsx("div",{className:"h-3 w-12 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsx("div",{className:"h-5 w-5 bg-muted rounded-md animate-pulse"})]})]})}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("div",{className:"h-3 w-8 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 w-32 bg-muted rounded-md animate-pulse"})]}),jsxRuntime.jsxs("div",{className:"flex items-start justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1 flex-1",children:[jsxRuntime.jsx("div",{className:"h-3 w-16 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 w-6 bg-muted rounded-md animate-pulse"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-1 flex-1 flex flex-col items-end",children:[jsxRuntime.jsx("div",{className:"h-3 w-20 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 bg-muted rounded-md animate-pulse"}),jsxRuntime.jsx("div",{className:"h-6 w-16 bg-muted rounded-md animate-pulse"})]})]})]})]})]}):jsxRuntime.jsx(Card,{children:jsxRuntime.jsxs(CardContent,{className:"grid grid-cols-[1fr_auto] items-start gap-4 pt-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-start gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Category Name"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold leading-none tracking-tight",children:e})]}),jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Niche"}),jsxRuntime.jsx("p",{className:"text-sm font-medium",children:t})]}),jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Products"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Package,{className:"h-4 w-4 text-muted-foreground"}),jsxRuntime.jsx("span",{className:"text-sm font-medium",children:n})]})]})]}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end justify-between gap-4 h-full",children:[f,jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Starred"}),l?jsxRuntime.jsx(Star,{className:"h-5 w-5 fill-yellow-400 text-yellow-400"}):jsxRuntime.jsx(Star,{className:"h-5 w-5 text-muted-foreground"})]}),jsxRuntime.jsxs("div",{className:"space-y-1 flex flex-col items-end",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Auto-reorder"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[o?jsxRuntime.jsx(RefreshCw,{className:"size-4 text-green-600"}):jsxRuntime.jsx(RefreshCwOff,{className:"size-4 text-amber-600"}),jsxRuntime.jsx(Badge,{variant:o?"default":"secondary",className:cn("text-xs",o?"text-green-600 bg-green-100 hover:bg-green-200":"text-amber-600 bg-amber-100 hover:bg-amber-200"),children:o?"Enabled":"Disabled"})]})]})]})]})})}function createSlot$1(e){const t=createSlotClone$1(e),n=React__namespace.forwardRef((o,l)=>{const{children:d,...f}=o,g=React__namespace.Children.toArray(d),b=g.find(isSlottable$1);if(b){const _=b.props.children,S=g.map(R=>R===b?React__namespace.Children.count(_)>1?React__namespace.Children.only(null):React__namespace.isValidElement(_)?_.props.children:null:R);return jsxRuntime.jsx(t,{...f,ref:l,children:React__namespace.isValidElement(_)?React__namespace.cloneElement(_,void 0,S):null})}return jsxRuntime.jsx(t,{...f,ref:l,children:d})});return n.displayName=`${e}.Slot`,n}function createSlotClone$1(e){const t=React__namespace.forwardRef((n,o)=>{const{children:l,...d}=n;if(React__namespace.isValidElement(l)){const f=getElementRef$1(l),g=mergeProps$1(d,l.props);return l.type!==React__namespace.Fragment&&(g.ref=o?composeRefs(o,f):f),React__namespace.cloneElement(l,g)}return React__namespace.Children.count(l)>1?React__namespace.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var SLOTTABLE_IDENTIFIER$2=Symbol("radix.slottable");function isSlottable$1(e){return React__namespace.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===SLOTTABLE_IDENTIFIER$2}function mergeProps$1(e,t){const n={...t};for(const o in t){const l=e[o],d=t[o];/^on[A-Z]/.test(o)?l&&d?n[o]=(...g)=>{const b=d(...g);return l(...g),b}:l&&(n[o]=l):o==="style"?n[o]={...l,...d}:o==="className"&&(n[o]=[l,d].filter(Boolean).join(" "))}return{...e,...n}}function getElementRef$1(e){var o,l;let t=(o=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(l=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:l.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var OPEN_KEYS=[" ","Enter","ArrowUp","ArrowDown"],SELECTION_KEYS=[" ","Enter"],SELECT_NAME="Select",[Collection$1,useCollection$1,createCollectionScope$1]=createCollection(SELECT_NAME),[createSelectContext]=createContextScope$2(SELECT_NAME,[createCollectionScope$1,createPopperScope]),usePopperScope$1=createPopperScope(),[SelectProvider,useSelectContext]=createSelectContext(SELECT_NAME),[SelectNativeOptionsProvider,useSelectNativeOptionsContext]=createSelectContext(SELECT_NAME),Select$2=e=>{const{__scopeSelect:t,children:n,open:o,defaultOpen:l,onOpenChange:d,value:f,defaultValue:g,onValueChange:b,dir:_,name:S,autoComplete:R,disabled:C,required:E,form:A}=e,M=usePopperScope$1(t),[I,j]=React__namespace.useState(null),[q,Q]=React__namespace.useState(null),[te,F]=React__namespace.useState(!1),V=useDirection(_),[ne,ae]=useControllableState({prop:o,defaultProp:l??!1,onChange:d,caller:SELECT_NAME}),[se,Oe]=useControllableState({prop:f,defaultProp:g,onChange:b,caller:SELECT_NAME}),Ne=React__namespace.useRef(null),oe=I?A||!!I.closest("form"):!0,[$e,Ae]=React__namespace.useState(new Set),je=Array.from($e).map(Be=>Be.props.value).join(";");return jsxRuntime.jsx(Root2$7,{...M,children:jsxRuntime.jsxs(SelectProvider,{required:E,scope:t,trigger:I,onTriggerChange:j,valueNode:q,onValueNodeChange:Q,valueNodeHasChildren:te,onValueNodeHasChildrenChange:F,contentId:useId(),value:se,onValueChange:Oe,open:ne,onOpenChange:ae,dir:V,triggerPointerDownPosRef:Ne,disabled:C,children:[jsxRuntime.jsx(Collection$1.Provider,{scope:t,children:jsxRuntime.jsx(SelectNativeOptionsProvider,{scope:e.__scopeSelect,onNativeOptionAdd:React__namespace.useCallback(Be=>{Ae(qe=>new Set(qe).add(Be))},[]),onNativeOptionRemove:React__namespace.useCallback(Be=>{Ae(qe=>{const Ve=new Set(qe);return Ve.delete(Be),Ve})},[]),children:n})}),oe?jsxRuntime.jsxs(SelectBubbleInput,{"aria-hidden":!0,required:E,tabIndex:-1,name:S,autoComplete:R,value:se,onChange:Be=>Oe(Be.target.value),disabled:C,form:A,children:[se===void 0?jsxRuntime.jsx("option",{value:""}):null,Array.from($e)]},je):null]})})};Select$2.displayName=SELECT_NAME;var TRIGGER_NAME$5="SelectTrigger",SelectTrigger$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:o=!1,...l}=e,d=usePopperScope$1(n),f=useSelectContext(TRIGGER_NAME$5,n),g=f.disabled||o,b=useComposedRefs(t,f.onTriggerChange),_=useCollection$1(n),S=React__namespace.useRef("touch"),[R,C,E]=useTypeaheadSearch(M=>{const I=_().filter(Q=>!Q.disabled),j=I.find(Q=>Q.value===f.value),q=findNextItem(I,M,j);q!==void 0&&f.onValueChange(q.value)}),A=M=>{g||(f.onOpenChange(!0),E()),M&&(f.triggerPointerDownPosRef.current={x:Math.round(M.pageX),y:Math.round(M.pageY)})};return jsxRuntime.jsx(Anchor,{asChild:!0,...d,children:jsxRuntime.jsx(Primitive$4.button,{type:"button",role:"combobox","aria-controls":f.contentId,"aria-expanded":f.open,"aria-required":f.required,"aria-autocomplete":"none",dir:f.dir,"data-state":f.open?"open":"closed",disabled:g,"data-disabled":g?"":void 0,"data-placeholder":shouldShowPlaceholder(f.value)?"":void 0,...l,ref:b,onClick:composeEventHandlers(l.onClick,M=>{M.currentTarget.focus(),S.current!=="mouse"&&A(M)}),onPointerDown:composeEventHandlers(l.onPointerDown,M=>{S.current=M.pointerType;const I=M.target;I.hasPointerCapture(M.pointerId)&&I.releasePointerCapture(M.pointerId),M.button===0&&M.ctrlKey===!1&&M.pointerType==="mouse"&&(A(M),M.preventDefault())}),onKeyDown:composeEventHandlers(l.onKeyDown,M=>{const I=R.current!=="";!(M.ctrlKey||M.altKey||M.metaKey)&&M.key.length===1&&C(M.key),!(I&&M.key===" ")&&OPEN_KEYS.includes(M.key)&&(A(),M.preventDefault())})})})});SelectTrigger$1.displayName=TRIGGER_NAME$5;var VALUE_NAME="SelectValue",SelectValue$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,className:o,style:l,children:d,placeholder:f="",...g}=e,b=useSelectContext(VALUE_NAME,n),{onValueNodeHasChildrenChange:_}=b,S=d!==void 0,R=useComposedRefs(t,b.onValueNodeChange);return useLayoutEffect2(()=>{_(S)},[_,S]),jsxRuntime.jsx(Primitive$4.span,{...g,ref:R,style:{pointerEvents:"none"},children:shouldShowPlaceholder(b.value)?jsxRuntime.jsx(jsxRuntime.Fragment,{children:f}):d})});SelectValue$1.displayName=VALUE_NAME;var ICON_NAME="SelectIcon",SelectIcon=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,children:o,...l}=e;return jsxRuntime.jsx(Primitive$4.span,{"aria-hidden":!0,...l,ref:t,children:o||"▼"})});SelectIcon.displayName=ICON_NAME;var PORTAL_NAME$2="SelectPortal",SelectPortal=e=>jsxRuntime.jsx(Portal$5,{asChild:!0,...e});SelectPortal.displayName=PORTAL_NAME$2;var CONTENT_NAME$4="SelectContent",SelectContent$1=React__namespace.forwardRef((e,t)=>{const n=useSelectContext(CONTENT_NAME$4,e.__scopeSelect),[o,l]=React__namespace.useState();if(useLayoutEffect2(()=>{l(new DocumentFragment)},[]),!n.open){const d=o;return d?ReactDOM__namespace.createPortal(jsxRuntime.jsx(SelectContentProvider,{scope:e.__scopeSelect,children:jsxRuntime.jsx(Collection$1.Slot,{scope:e.__scopeSelect,children:jsxRuntime.jsx("div",{children:e.children})})}),d):null}return jsxRuntime.jsx(SelectContentImpl,{...e,ref:t})});SelectContent$1.displayName=CONTENT_NAME$4;var CONTENT_MARGIN=10,[SelectContentProvider,useSelectContentContext]=createSelectContext(CONTENT_NAME$4),CONTENT_IMPL_NAME="SelectContentImpl",Slot$1=createSlot$1("SelectContent.RemoveScroll"),SelectContentImpl=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,position:o="item-aligned",onCloseAutoFocus:l,onEscapeKeyDown:d,onPointerDownOutside:f,side:g,sideOffset:b,align:_,alignOffset:S,arrowPadding:R,collisionBoundary:C,collisionPadding:E,sticky:A,hideWhenDetached:M,avoidCollisions:I,...j}=e,q=useSelectContext(CONTENT_NAME$4,n),[Q,te]=React__namespace.useState(null),[F,V]=React__namespace.useState(null),ne=useComposedRefs(t,et=>te(et)),[ae,se]=React__namespace.useState(null),[Oe,Ne]=React__namespace.useState(null),oe=useCollection$1(n),[$e,Ae]=React__namespace.useState(!1),je=React__namespace.useRef(!1);React__namespace.useEffect(()=>{if(Q)return hideOthers(Q)},[Q]),useFocusGuards();const Be=React__namespace.useCallback(et=>{const[at,...tt]=oe().map(Ge=>Ge.ref.current),[ot]=tt.slice(-1),lt=document.activeElement;for(const Ge of et)if(Ge===lt||(Ge==null||Ge.scrollIntoView({block:"nearest"}),Ge===at&&F&&(F.scrollTop=0),Ge===ot&&F&&(F.scrollTop=F.scrollHeight),Ge==null||Ge.focus(),document.activeElement!==lt))return},[oe,F]),qe=React__namespace.useCallback(()=>Be([ae,Q]),[Be,ae,Q]);React__namespace.useEffect(()=>{$e&&qe()},[$e,qe]);const{onOpenChange:Ve,triggerPointerDownPosRef:Le}=q;React__namespace.useEffect(()=>{if(Q){let et={x:0,y:0};const at=ot=>{var lt,Ge;et={x:Math.abs(Math.round(ot.pageX)-(((lt=Le.current)==null?void 0:lt.x)??0)),y:Math.abs(Math.round(ot.pageY)-(((Ge=Le.current)==null?void 0:Ge.y)??0))}},tt=ot=>{et.x<=10&&et.y<=10?ot.preventDefault():Q.contains(ot.target)||Ve(!1),document.removeEventListener("pointermove",at),Le.current=null};return Le.current!==null&&(document.addEventListener("pointermove",at),document.addEventListener("pointerup",tt,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",at),document.removeEventListener("pointerup",tt,{capture:!0})}}},[Q,Ve,Le]),React__namespace.useEffect(()=>{const et=()=>Ve(!1);return window.addEventListener("blur",et),window.addEventListener("resize",et),()=>{window.removeEventListener("blur",et),window.removeEventListener("resize",et)}},[Ve]);const[He,We]=useTypeaheadSearch(et=>{const at=oe().filter(lt=>!lt.disabled),tt=at.find(lt=>lt.ref.current===document.activeElement),ot=findNextItem(at,et,tt);ot&&setTimeout(()=>ot.ref.current.focus())}),ze=React__namespace.useCallback((et,at,tt)=>{const ot=!je.current&&!tt;(q.value!==void 0&&q.value===at||ot)&&(se(et),ot&&(je.current=!0))},[q.value]),Xe=React__namespace.useCallback(()=>Q==null?void 0:Q.focus(),[Q]),nt=React__namespace.useCallback((et,at,tt)=>{const ot=!je.current&&!tt;(q.value!==void 0&&q.value===at||ot)&&Ne(et)},[q.value]),Je=o==="popper"?SelectPopperPosition:SelectItemAlignedPosition,st=Je===SelectPopperPosition?{side:g,sideOffset:b,align:_,alignOffset:S,arrowPadding:R,collisionBoundary:C,collisionPadding:E,sticky:A,hideWhenDetached:M,avoidCollisions:I}:{};return jsxRuntime.jsx(SelectContentProvider,{scope:n,content:Q,viewport:F,onViewportChange:V,itemRefCallback:ze,selectedItem:ae,onItemLeave:Xe,itemTextRefCallback:nt,focusSelectedItem:qe,selectedItemText:Oe,position:o,isPositioned:$e,searchRef:He,children:jsxRuntime.jsx(ReactRemoveScroll,{as:Slot$1,allowPinchZoom:!0,children:jsxRuntime.jsx(FocusScope,{asChild:!0,trapped:q.open,onMountAutoFocus:et=>{et.preventDefault()},onUnmountAutoFocus:composeEventHandlers(l,et=>{var at;(at=q.trigger)==null||at.focus({preventScroll:!0}),et.preventDefault()}),children:jsxRuntime.jsx(DismissableLayer,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:et=>et.preventDefault(),onDismiss:()=>q.onOpenChange(!1),children:jsxRuntime.jsx(Je,{role:"listbox",id:q.contentId,"data-state":q.open?"open":"closed",dir:q.dir,onContextMenu:et=>et.preventDefault(),...j,...st,onPlaced:()=>Ae(!0),ref:ne,style:{display:"flex",flexDirection:"column",outline:"none",...j.style},onKeyDown:composeEventHandlers(j.onKeyDown,et=>{const at=et.ctrlKey||et.altKey||et.metaKey;if(et.key==="Tab"&&et.preventDefault(),!at&&et.key.length===1&&We(et.key),["ArrowUp","ArrowDown","Home","End"].includes(et.key)){let ot=oe().filter(lt=>!lt.disabled).map(lt=>lt.ref.current);if(["ArrowUp","End"].includes(et.key)&&(ot=ot.slice().reverse()),["ArrowUp","ArrowDown"].includes(et.key)){const lt=et.target,Ge=ot.indexOf(lt);ot=ot.slice(Ge+1)}setTimeout(()=>Be(ot)),et.preventDefault()}})})})})})})});SelectContentImpl.displayName=CONTENT_IMPL_NAME;var ITEM_ALIGNED_POSITION_NAME="SelectItemAlignedPosition",SelectItemAlignedPosition=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:o,...l}=e,d=useSelectContext(CONTENT_NAME$4,n),f=useSelectContentContext(CONTENT_NAME$4,n),[g,b]=React__namespace.useState(null),[_,S]=React__namespace.useState(null),R=useComposedRefs(t,ne=>S(ne)),C=useCollection$1(n),E=React__namespace.useRef(!1),A=React__namespace.useRef(!0),{viewport:M,selectedItem:I,selectedItemText:j,focusSelectedItem:q}=f,Q=React__namespace.useCallback(()=>{if(d.trigger&&d.valueNode&&g&&_&&M&&I&&j){const ne=d.trigger.getBoundingClientRect(),ae=_.getBoundingClientRect(),se=d.valueNode.getBoundingClientRect(),Oe=j.getBoundingClientRect();if(d.dir!=="rtl"){const lt=Oe.left-ae.left,Ge=se.left-lt,$t=ne.left-Ge,rt=ne.width+$t,Rt=Math.max(rt,ae.width),dt=window.innerWidth-CONTENT_MARGIN,It=clamp(Ge,[CONTENT_MARGIN,Math.max(CONTENT_MARGIN,dt-Rt)]);g.style.minWidth=rt+"px",g.style.left=It+"px"}else{const lt=ae.right-Oe.right,Ge=window.innerWidth-se.right-lt,$t=window.innerWidth-ne.right-Ge,rt=ne.width+$t,Rt=Math.max(rt,ae.width),dt=window.innerWidth-CONTENT_MARGIN,It=clamp(Ge,[CONTENT_MARGIN,Math.max(CONTENT_MARGIN,dt-Rt)]);g.style.minWidth=rt+"px",g.style.right=It+"px"}const Ne=C(),oe=window.innerHeight-CONTENT_MARGIN*2,$e=M.scrollHeight,Ae=window.getComputedStyle(_),je=parseInt(Ae.borderTopWidth,10),Be=parseInt(Ae.paddingTop,10),qe=parseInt(Ae.borderBottomWidth,10),Ve=parseInt(Ae.paddingBottom,10),Le=je+Be+$e+Ve+qe,He=Math.min(I.offsetHeight*5,Le),We=window.getComputedStyle(M),ze=parseInt(We.paddingTop,10),Xe=parseInt(We.paddingBottom,10),nt=ne.top+ne.height/2-CONTENT_MARGIN,Je=oe-nt,st=I.offsetHeight/2,et=I.offsetTop+st,at=je+Be+et,tt=Le-at;if(at<=nt){const lt=Ne.length>0&&I===Ne[Ne.length-1].ref.current;g.style.bottom="0px";const Ge=_.clientHeight-M.offsetTop-M.offsetHeight,$t=Math.max(Je,st+(lt?Xe:0)+Ge+qe),rt=at+$t;g.style.height=rt+"px"}else{const lt=Ne.length>0&&I===Ne[0].ref.current;g.style.top="0px";const $t=Math.max(nt,je+M.offsetTop+(lt?ze:0)+st)+tt;g.style.height=$t+"px",M.scrollTop=at-nt+M.offsetTop}g.style.margin=`${CONTENT_MARGIN}px 0`,g.style.minHeight=He+"px",g.style.maxHeight=oe+"px",o==null||o(),requestAnimationFrame(()=>E.current=!0)}},[C,d.trigger,d.valueNode,g,_,M,I,j,d.dir,o]);useLayoutEffect2(()=>Q(),[Q]);const[te,F]=React__namespace.useState();useLayoutEffect2(()=>{_&&F(window.getComputedStyle(_).zIndex)},[_]);const V=React__namespace.useCallback(ne=>{ne&&A.current===!0&&(Q(),q==null||q(),A.current=!1)},[Q,q]);return jsxRuntime.jsx(SelectViewportProvider,{scope:n,contentWrapper:g,shouldExpandOnScrollRef:E,onScrollButtonChange:V,children:jsxRuntime.jsx("div",{ref:b,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:te},children:jsxRuntime.jsx(Primitive$4.div,{...l,ref:R,style:{boxSizing:"border-box",maxHeight:"100%",...l.style}})})})});SelectItemAlignedPosition.displayName=ITEM_ALIGNED_POSITION_NAME;var POPPER_POSITION_NAME="SelectPopperPosition",SelectPopperPosition=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,align:o="start",collisionPadding:l=CONTENT_MARGIN,...d}=e,f=usePopperScope$1(n);return jsxRuntime.jsx(Content$2,{...f,...d,ref:t,align:o,collisionPadding:l,style:{boxSizing:"border-box",...d.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});SelectPopperPosition.displayName=POPPER_POSITION_NAME;var[SelectViewportProvider,useSelectViewportContext]=createSelectContext(CONTENT_NAME$4,{}),VIEWPORT_NAME="SelectViewport",SelectViewport=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:o,...l}=e,d=useSelectContentContext(VIEWPORT_NAME,n),f=useSelectViewportContext(VIEWPORT_NAME,n),g=useComposedRefs(t,d.onViewportChange),b=React__namespace.useRef(0);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),jsxRuntime.jsx(Collection$1.Slot,{scope:n,children:jsxRuntime.jsx(Primitive$4.div,{"data-radix-select-viewport":"",role:"presentation",...l,ref:g,style:{position:"relative",flex:1,overflow:"hidden auto",...l.style},onScroll:composeEventHandlers(l.onScroll,_=>{const S=_.currentTarget,{contentWrapper:R,shouldExpandOnScrollRef:C}=f;if(C!=null&&C.current&&R){const E=Math.abs(b.current-S.scrollTop);if(E>0){const A=window.innerHeight-CONTENT_MARGIN*2,M=parseFloat(R.style.minHeight),I=parseFloat(R.style.height),j=Math.max(M,I);if(j<A){const q=j+E,Q=Math.min(A,q),te=q-Q;R.style.height=Q+"px",R.style.bottom==="0px"&&(S.scrollTop=te>0?te:0,R.style.justifyContent="flex-end")}}}b.current=S.scrollTop})})})]})});SelectViewport.displayName=VIEWPORT_NAME;var GROUP_NAME="SelectGroup",[SelectGroupContextProvider,useSelectGroupContext]=createSelectContext(GROUP_NAME),SelectGroup$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,...o}=e,l=useId();return jsxRuntime.jsx(SelectGroupContextProvider,{scope:n,id:l,children:jsxRuntime.jsx(Primitive$4.div,{role:"group","aria-labelledby":l,...o,ref:t})})});SelectGroup$1.displayName=GROUP_NAME;var LABEL_NAME="SelectLabel",SelectLabel$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,...o}=e,l=useSelectGroupContext(LABEL_NAME,n);return jsxRuntime.jsx(Primitive$4.div,{id:l.id,...o,ref:t})});SelectLabel$1.displayName=LABEL_NAME;var ITEM_NAME$1="SelectItem",[SelectItemContextProvider,useSelectItemContext]=createSelectContext(ITEM_NAME$1),SelectItem$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,value:o,disabled:l=!1,textValue:d,...f}=e,g=useSelectContext(ITEM_NAME$1,n),b=useSelectContentContext(ITEM_NAME$1,n),_=g.value===o,[S,R]=React__namespace.useState(d??""),[C,E]=React__namespace.useState(!1),A=useComposedRefs(t,q=>{var Q;return(Q=b.itemRefCallback)==null?void 0:Q.call(b,q,o,l)}),M=useId(),I=React__namespace.useRef("touch"),j=()=>{l||(g.onValueChange(o),g.onOpenChange(!1))};if(o==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return jsxRuntime.jsx(SelectItemContextProvider,{scope:n,value:o,disabled:l,textId:M,isSelected:_,onItemTextChange:React__namespace.useCallback(q=>{R(Q=>Q||((q==null?void 0:q.textContent)??"").trim())},[]),children:jsxRuntime.jsx(Collection$1.ItemSlot,{scope:n,value:o,disabled:l,textValue:S,children:jsxRuntime.jsx(Primitive$4.div,{role:"option","aria-labelledby":M,"data-highlighted":C?"":void 0,"aria-selected":_&&C,"data-state":_?"checked":"unchecked","aria-disabled":l||void 0,"data-disabled":l?"":void 0,tabIndex:l?void 0:-1,...f,ref:A,onFocus:composeEventHandlers(f.onFocus,()=>E(!0)),onBlur:composeEventHandlers(f.onBlur,()=>E(!1)),onClick:composeEventHandlers(f.onClick,()=>{I.current!=="mouse"&&j()}),onPointerUp:composeEventHandlers(f.onPointerUp,()=>{I.current==="mouse"&&j()}),onPointerDown:composeEventHandlers(f.onPointerDown,q=>{I.current=q.pointerType}),onPointerMove:composeEventHandlers(f.onPointerMove,q=>{var Q;I.current=q.pointerType,l?(Q=b.onItemLeave)==null||Q.call(b):I.current==="mouse"&&q.currentTarget.focus({preventScroll:!0})}),onPointerLeave:composeEventHandlers(f.onPointerLeave,q=>{var Q;q.currentTarget===document.activeElement&&((Q=b.onItemLeave)==null||Q.call(b))}),onKeyDown:composeEventHandlers(f.onKeyDown,q=>{var te;((te=b.searchRef)==null?void 0:te.current)!==""&&q.key===" "||(SELECTION_KEYS.includes(q.key)&&j(),q.key===" "&&q.preventDefault())})})})})});SelectItem$1.displayName=ITEM_NAME$1;var ITEM_TEXT_NAME="SelectItemText",SelectItemText=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,className:o,style:l,...d}=e,f=useSelectContext(ITEM_TEXT_NAME,n),g=useSelectContentContext(ITEM_TEXT_NAME,n),b=useSelectItemContext(ITEM_TEXT_NAME,n),_=useSelectNativeOptionsContext(ITEM_TEXT_NAME,n),[S,R]=React__namespace.useState(null),C=useComposedRefs(t,j=>R(j),b.onItemTextChange,j=>{var q;return(q=g.itemTextRefCallback)==null?void 0:q.call(g,j,b.value,b.disabled)}),E=S==null?void 0:S.textContent,A=React__namespace.useMemo(()=>jsxRuntime.jsx("option",{value:b.value,disabled:b.disabled,children:E},b.value),[b.disabled,b.value,E]),{onNativeOptionAdd:M,onNativeOptionRemove:I}=_;return useLayoutEffect2(()=>(M(A),()=>I(A)),[M,I,A]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Primitive$4.span,{id:b.textId,...d,ref:C}),b.isSelected&&f.valueNode&&!f.valueNodeHasChildren?ReactDOM__namespace.createPortal(d.children,f.valueNode):null]})});SelectItemText.displayName=ITEM_TEXT_NAME;var ITEM_INDICATOR_NAME="SelectItemIndicator",SelectItemIndicator=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,...o}=e;return useSelectItemContext(ITEM_INDICATOR_NAME,n).isSelected?jsxRuntime.jsx(Primitive$4.span,{"aria-hidden":!0,...o,ref:t}):null});SelectItemIndicator.displayName=ITEM_INDICATOR_NAME;var SCROLL_UP_BUTTON_NAME="SelectScrollUpButton",SelectScrollUpButton$1=React__namespace.forwardRef((e,t)=>{const n=useSelectContentContext(SCROLL_UP_BUTTON_NAME,e.__scopeSelect),o=useSelectViewportContext(SCROLL_UP_BUTTON_NAME,e.__scopeSelect),[l,d]=React__namespace.useState(!1),f=useComposedRefs(t,o.onScrollButtonChange);return useLayoutEffect2(()=>{if(n.viewport&&n.isPositioned){let g=function(){const _=b.scrollTop>0;d(_)};const b=n.viewport;return g(),b.addEventListener("scroll",g),()=>b.removeEventListener("scroll",g)}},[n.viewport,n.isPositioned]),l?jsxRuntime.jsx(SelectScrollButtonImpl,{...e,ref:f,onAutoScroll:()=>{const{viewport:g,selectedItem:b}=n;g&&b&&(g.scrollTop=g.scrollTop-b.offsetHeight)}}):null});SelectScrollUpButton$1.displayName=SCROLL_UP_BUTTON_NAME;var SCROLL_DOWN_BUTTON_NAME="SelectScrollDownButton",SelectScrollDownButton$1=React__namespace.forwardRef((e,t)=>{const n=useSelectContentContext(SCROLL_DOWN_BUTTON_NAME,e.__scopeSelect),o=useSelectViewportContext(SCROLL_DOWN_BUTTON_NAME,e.__scopeSelect),[l,d]=React__namespace.useState(!1),f=useComposedRefs(t,o.onScrollButtonChange);return useLayoutEffect2(()=>{if(n.viewport&&n.isPositioned){let g=function(){const _=b.scrollHeight-b.clientHeight,S=Math.ceil(b.scrollTop)<_;d(S)};const b=n.viewport;return g(),b.addEventListener("scroll",g),()=>b.removeEventListener("scroll",g)}},[n.viewport,n.isPositioned]),l?jsxRuntime.jsx(SelectScrollButtonImpl,{...e,ref:f,onAutoScroll:()=>{const{viewport:g,selectedItem:b}=n;g&&b&&(g.scrollTop=g.scrollTop+b.offsetHeight)}}):null});SelectScrollDownButton$1.displayName=SCROLL_DOWN_BUTTON_NAME;var SelectScrollButtonImpl=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:o,...l}=e,d=useSelectContentContext("SelectScrollButton",n),f=React__namespace.useRef(null),g=useCollection$1(n),b=React__namespace.useCallback(()=>{f.current!==null&&(window.clearInterval(f.current),f.current=null)},[]);return React__namespace.useEffect(()=>()=>b(),[b]),useLayoutEffect2(()=>{var S;const _=g().find(R=>R.ref.current===document.activeElement);(S=_==null?void 0:_.ref.current)==null||S.scrollIntoView({block:"nearest"})},[g]),jsxRuntime.jsx(Primitive$4.div,{"aria-hidden":!0,...l,ref:t,style:{flexShrink:0,...l.style},onPointerDown:composeEventHandlers(l.onPointerDown,()=>{f.current===null&&(f.current=window.setInterval(o,50))}),onPointerMove:composeEventHandlers(l.onPointerMove,()=>{var _;(_=d.onItemLeave)==null||_.call(d),f.current===null&&(f.current=window.setInterval(o,50))}),onPointerLeave:composeEventHandlers(l.onPointerLeave,()=>{b()})})}),SEPARATOR_NAME="SelectSeparator",SelectSeparator$1=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,...o}=e;return jsxRuntime.jsx(Primitive$4.div,{"aria-hidden":!0,...o,ref:t})});SelectSeparator$1.displayName=SEPARATOR_NAME;var ARROW_NAME$1="SelectArrow",SelectArrow=React__namespace.forwardRef((e,t)=>{const{__scopeSelect:n,...o}=e,l=usePopperScope$1(n),d=useSelectContext(ARROW_NAME$1,n),f=useSelectContentContext(ARROW_NAME$1,n);return d.open&&f.position==="popper"?jsxRuntime.jsx(Arrow,{...l,...o,ref:t}):null});SelectArrow.displayName=ARROW_NAME$1;var BUBBLE_INPUT_NAME$1="SelectBubbleInput",SelectBubbleInput=React__namespace.forwardRef(({__scopeSelect:e,value:t,...n},o)=>{const l=React__namespace.useRef(null),d=useComposedRefs(o,l),f=usePrevious(t);return React__namespace.useEffect(()=>{const g=l.current;if(!g)return;const b=window.HTMLSelectElement.prototype,S=Object.getOwnPropertyDescriptor(b,"value").set;if(f!==t&&S){const R=new Event("change",{bubbles:!0});S.call(g,t),g.dispatchEvent(R)}},[f,t]),jsxRuntime.jsx(Primitive$4.select,{...n,style:{...VISUALLY_HIDDEN_STYLES,...n.style},ref:d,defaultValue:t})});SelectBubbleInput.displayName=BUBBLE_INPUT_NAME$1;function shouldShowPlaceholder(e){return e===""||e===void 0}function useTypeaheadSearch(e){const t=useCallbackRef$1(e),n=React__namespace.useRef(""),o=React__namespace.useRef(0),l=React__namespace.useCallback(f=>{const g=n.current+f;t(g),(function b(_){n.current=_,window.clearTimeout(o.current),_!==""&&(o.current=window.setTimeout(()=>b(""),1e3))})(g)},[t]),d=React__namespace.useCallback(()=>{n.current="",window.clearTimeout(o.current)},[]);return React__namespace.useEffect(()=>()=>window.clearTimeout(o.current),[]),[n,l,d]}function findNextItem(e,t,n){const l=t.length>1&&Array.from(t).every(_=>_===t[0])?t[0]:t,d=n?e.indexOf(n):-1;let f=wrapArray(e,Math.max(d,0));l.length===1&&(f=f.filter(_=>_!==n));const b=f.find(_=>_.textValue.toLowerCase().startsWith(l.toLowerCase()));return b!==n?b:void 0}function wrapArray(e,t){return e.map((n,o)=>e[(t+o)%e.length])}var Root2$3=Select$2,Trigger$2=SelectTrigger$1,Value=SelectValue$1,Icon=SelectIcon,Portal$1=SelectPortal,Content2$3=SelectContent$1,Viewport=SelectViewport,Group=SelectGroup$1,Label=SelectLabel$1,Item$2=SelectItem$1,ItemText=SelectItemText,ItemIndicator=SelectItemIndicator,ScrollUpButton=SelectScrollUpButton$1,ScrollDownButton=SelectScrollDownButton$1,Separator=SelectSeparator$1;const Select$1=Root2$3,SelectGroup=Group,SelectValue=Value,SelectTrigger=React__namespace.forwardRef(({className:e,children:t,...n},o)=>jsxRuntime.jsxs(Trigger$2,{ref:o,className:cn("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,jsxRuntime.jsx(Icon,{asChild:!0,children:jsxRuntime.jsx(ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));SelectTrigger.displayName=Trigger$2.displayName;const SelectScrollUpButton=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx(ScrollUpButton,{ref:n,className:cn("flex cursor-default items-center justify-center py-1",e),...t,children:jsxRuntime.jsx(ChevronUp,{className:"h-4 w-4"})}));SelectScrollUpButton.displayName=ScrollUpButton.displayName;const SelectScrollDownButton=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx(ScrollDownButton,{ref:n,className:cn("flex cursor-default items-center justify-center py-1",e),...t,children:jsxRuntime.jsx(ChevronDown,{className:"h-4 w-4"})}));SelectScrollDownButton.displayName=ScrollDownButton.displayName;const SelectContent=React__namespace.forwardRef(({className:e,children:t,position:n="popper",...o},l)=>jsxRuntime.jsx(Portal$1,{children:jsxRuntime.jsxs(Content2$3,{ref:l,className:cn("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...o,children:[jsxRuntime.jsx(SelectScrollUpButton,{}),jsxRuntime.jsx(Viewport,{className:cn("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),jsxRuntime.jsx(SelectScrollDownButton,{})]})}));SelectContent.displayName=Content2$3.displayName;const SelectLabel=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx(Label,{ref:n,className:cn("px-2 py-1.5 text-sm font-semibold",e),...t}));SelectLabel.displayName=Label.displayName;const SelectItem=React__namespace.forwardRef(({className:e,children:t,...n},o)=>jsxRuntime.jsxs(Item$2,{ref:o,className:cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[jsxRuntime.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:jsxRuntime.jsx(ItemIndicator,{children:jsxRuntime.jsx(Check,{className:"h-4 w-4"})})}),jsxRuntime.jsx(ItemText,{children:t})]}));SelectItem.displayName=Item$2.displayName;const SelectSeparator=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx(Separator,{ref:n,className:cn("-mx-1 my-1 h-px bg-muted",e),...t}));SelectSeparator.displayName=Separator.displayName;function ManufacturerProducts({applicationId:e,manufacturer:t,shopifyHostName:n}){var Q,te,F,V,ne;const[o]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[l,d]=React.useState(((te=(Q=t.Categories)==null?void 0:Q[0])==null?void 0:te.CategoryCode)||""),[f,g]=React.useState(!1),[b,_]=React.useState(!1),[S,R]=React.useState("percentile"),{toast:C}=useToast(),{data:E,isLoading:A,isFetching:M}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:e,manufacturerId:t.ManufacturerId,categoryCode:l??""},{skip:!t.ManufacturerId||!l}),I=async()=>{try{g(!0),_(!1),await o({routeResellerId:e,manufacturerId:t.ManufacturerId??"",categoryCode:l,shopifyHostName:n}).unwrap()&&C({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(ae){console.error("Error syncing to Shopify:",ae),C({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{g(!1)}},j=()=>{var ae,se;return((se=(ae=t.Categories)==null?void 0:ae.find(Oe=>Oe.CategoryCode===l))==null?void 0:se.CategoryName)||l},q=React.useMemo(()=>E!=null&&E.Products?[...E.Products].sort((ae,se)=>S==="price-asc"?(ae.MAP??0)-(se.MAP??0):S==="price-desc"?(se.MAP??0)-(ae.MAP??0):S==="name"?(ae.Title??"").localeCompare(se.Title??""):S==="percentile"?(se.OverallPercentileRank??0)-(ae.OverallPercentileRank??0):0):[],[E==null?void 0:E.Products,S]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"mb-4",children:[jsxRuntime.jsx(ManufacturerCategories,{categories:t.Categories||[],activeCategory:l,onSelectCategory:d}),jsxRuntime.jsx("div",{className:"mb-4 w-full",children:jsxRuntime.jsx(ManufacturerCategorySummary,{name:j(),niche:(E==null?void 0:E.Niche)||"",productsNumber:((F=E==null?void 0:E.Products)==null?void 0:F.length)||0,autoreorder:(E==null?void 0:E.AutoReorder)||!1,starred:(E==null?void 0:E.Starred)||!1,isLoading:A||M,children:n&&((V=t.Categories)==null?void 0:V.findIndex(ae=>ae.AvailableToBuy))!==-1&&jsxRuntime.jsx(Button$1,{className:"bg-green-600 hover:bg-green-700",disabled:f,onClick:()=>_(!0),children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Category to Shopify"]})})})}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsx(ManufacturerCategoriesStats,{categories:[(ne=t.Categories)==null?void 0:ne.find(ae=>ae.CategoryCode===l)].filter(Boolean),manufID:t.ManufacturerId,appID:e}),jsxRuntime.jsx(ActiveOrdersCard,{orders:(E==null?void 0:E.ActiveOrderDetails)??void 0,loading:A||M})]})]}),jsxRuntime.jsx(ManufacturerCategories,{categories:t.Categories||[],activeCategory:l,onSelectCategory:d}),jsxRuntime.jsxs("div",{className:"flex justify-between items-center mt-7 mb-4",children:[jsxRuntime.jsx("h4",{className:"text-xl md:text-2xl text-foreground font-bold",children:"Products"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 ms-auto",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Sort by:"}),jsxRuntime.jsxs(Select$1,{value:S,onValueChange:R,children:[jsxRuntime.jsx(SelectTrigger,{className:"w-[220px]",children:jsxRuntime.jsx(SelectValue,{})}),jsxRuntime.jsxs(SelectContent,{children:[jsxRuntime.jsx(SelectItem,{value:"price-asc",children:"MAP: Low to High"}),jsxRuntime.jsx(SelectItem,{value:"price-desc",children:"MAP: High to Low"}),jsxRuntime.jsx(SelectItem,{value:"name",children:"Name"}),jsxRuntime.jsx(SelectItem,{value:"percentile",children:"Best Selling"})]})]})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4 mb-4",children:A||M?Array.from({length:4}).map((ae,se)=>jsxRuntime.jsx(ProductCard,{},se)):q.length>0?q.map(ae=>jsxRuntime.jsx(ProductCard,{applicationId:e,product:ae,viewProductLink:`/${e}/Product/${ae.RandmarSKU}`,shopifyHostname:n},ae.RandmarSKU)):jsxRuntime.jsxs(Alert,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Warning"}),jsxRuntime.jsx(AlertDescription,{children:"No products found for this manufacturer category."})]})}),jsxRuntime.jsx(Dialog,{open:b,onOpenChange:_,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the category "',j(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{className:"bg-green-600 hover:bg-green-700",onClick:I,disabled:f,children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})})]})}function PartnerRelationshipPage({applicationId:e,partnerId:t,userEmail:n,shopifyHostName:o,isSuperAdmin:l}){var q,Q,te;const{data:d}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:e}),{data:f,isLoading:g,isFetching:b}=useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({routeApplicationId:e,partnerId:t,withSpecification:!0}),{toast:_}=useToast(),[S]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[R,C]=React.useState(!1),[E,A]=React.useState(!1),M=async()=>{try{C(!0),A(!1),await S({routeResellerId:e??"",manufacturerId:t??"",shopifyHostName:o}).unwrap()&&_({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(F){console.error("Error syncing to Shopify:",F),_({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{C(!1)}},I=()=>f!=null&&f.Manufacturer?"products":f!=null&&f.Reseller?"reseller-overview":"",j=usePartnershipAssistantPrompt(d,f);return jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 @2xl:grid-cols-2",children:[jsxRuntime.jsx(PartnerCard,{account:f,loading:g||b,withAbout:!0,withVoice:!1,action:" "}),jsxRuntime.jsxs("div",{className:"grid gap-4",children:[((f==null?void 0:f.Manufacturer)||g||b)&&jsxRuntime.jsx(ManufacturerCard,{manufacturer:f==null?void 0:f.Manufacturer,loading:g||b,mainAction:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(f==null?void 0:f.Manufacturer)&&jsxRuntime.jsx(ManufacturerGetStartedButton,{applicationId:e,manufacturer:f==null?void 0:f.Manufacturer}),o&&((Q=(q=f==null?void 0:f.Manufacturer)==null?void 0:q.Categories)==null?void 0:Q.findIndex(F=>F.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:E,onOpenChange:A,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{className:"bg-green-600 hover:bg-green-700 ml-2",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Manufacturer to Shopify"]})})}),jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the manufacturer "',(te=f==null?void 0:f.Manufacturer)==null?void 0:te.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{className:"bg-green-600 hover:bg-green-700",onClick:M,disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),(f==null?void 0:f.Reseller)&&jsxRuntime.jsx(ResellerCard,{reseller:f==null?void 0:f.Reseller,loading:g||b})]})]}),((f==null?void 0:f.Reseller)||(f==null?void 0:f.Manufacturer))&&!g&&!b&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4",children:jsxRuntime.jsxs(Tabs,{defaultValue:I(),className:"w-full",children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[(f==null?void 0:f.Reseller)&&jsxRuntime.jsx(TabsTrigger,{value:"reseller-overview",className:"reseller-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Reseller Overview"}),(f==null?void 0:f.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"manufacturer-overview",className:"manufacturer-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Manufacturer Overview"}),(f==null?void 0:f.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"products",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Products"}),jsxRuntime.jsxs(TabsTrigger,{value:"assistant",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:[jsxRuntime.jsx(Bot,{className:"mr-2 w-4 h-4"}),"Assistant"]})]}),(f==null?void 0:f.Reseller)&&jsxRuntime.jsx(TabsContent,{value:"reseller-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ResellerOverview,{readonly:!0,appID:f.ApplicationId||"",reseller:f==null?void 0:f.Reseller,userEmail:n,isSuperAdmin:l,withoutReports:!0})})}),(f==null?void 0:f.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"manufacturer-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerOverviewPage,{readonly:!0,manufacturer:f==null?void 0:f.Manufacturer,applicationId:e,userEmail:n})})}),(f==null?void 0:f.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"products",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerProducts,{applicationId:e,manufacturer:f.Manufacturer,shopifyHostName:o})})}),jsxRuntime.jsx(TabsContent,{value:"assistant",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(AssistantInsight,{prompt:j,thinkingPlaceholderText:"Thinking about the relationship..."})})})]})}),(g||b)&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4 mt-4 flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})})]})}const PublicInfo=({reseller:e,appID:t,isLoading:n,readonly:o,onUnsavedChanges:l})=>{const{toast:d}=useToast(),[f]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),[g,b]=React.useState({}),_=React.useMemo(()=>({publicEmail:e.PublicEmail??"",contactName:e.ContactName??"",phone:e.Phone??"",website:e.Website??""}),[e]),{register:S,handleSubmit:R,reset:C,watch:E,formState:{errors:A,isSubmitting:M}}=useForm({defaultValues:_}),I=E(),j=React.useCallback(()=>g?JSON.stringify(I)!==JSON.stringify(g):!1,[I,g]);React.useEffect(()=>{l&&l(j())},[j,l]),React.useEffect(()=>{e&&Object.keys(e).length>0&&(C(_),b(_))},[e,C,_]);const q=async te=>{let F=!0,V=!1;const ne=Object.keys(te).map(ae=>({key:ae,keyApi:ae.charAt(0).toUpperCase()+ae.slice(1)}));for(const ae of ne){const se=te[ae.key],Oe=e[ae.keyApi];if(se!==Oe&&se!==void 0){V=!0;try{await f({applicationId:t,fieldName:ae.keyApi,newValue:String(se)}).unwrap()||(F=!1)}catch(Ne){console.error(`Error updating ${ae.keyApi}:`,Ne),F=!1}}}F&&V?(d({title:"Public info",description:"Information updated successfully",variant:"success"}),b({...te}),l&&l(!1)):F||d({title:"Updation error",description:"Failed to update",variant:"destructive"})},Q=te=>!te||te.trim()==="";return n?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Public Information"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})})]})})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{className:"text-1xl font-bold",children:["Public Information ",o?"(read only)":""]})}),jsxRuntime.jsxs(CardContent,{children:[(Q(E("contactName"))||Q(E("publicEmail"))||Q(E("website"))||Q(E("phone")))&&jsxRuntime.jsxs(Alert,{variant:"destructive",className:"mb-6",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Missing information"}),jsxRuntime.jsx(AlertDescription,{children:"All fields are required to get started at working with Manufacturers."})]}),jsxRuntime.jsxs("form",{onSubmit:R(q),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"contactName",children:"Main Representative *"}),jsxRuntime.jsx(Input,{id:"contactName",placeholder:"John Doe",readOnly:o,...S("contactName",{}),className:A.contactName||Q(E("contactName"))?"input-error-indicator":""}),A.contactName&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.contactName.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"publicEmail",children:"Public Email *"}),jsxRuntime.jsx(Input,{id:"publicEmail",placeholder:"contact@company.com",readOnly:o,...S("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:A.publicEmail||Q(E("publicEmail"))?"input-error-indicator":""}),A.publicEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.publicEmail.message})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),jsxRuntime.jsx(Input,{id:"website",placeholder:"https://company.com",readOnly:o,...S("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.website||Q(E("website"))?"input-error-indicator":""}),A.website&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.website.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone Number *"}),jsxRuntime.jsx(Input,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:o,...S("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.phone||Q(E("phone"))?"input-error-indicator":""}),A.phone&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.phone.message})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button$1,{type:"submit",disabled:M||o,className:o?"hidden":"",children:M?"Saving...":"Save"})})]})]})]})};function BillingCard({appID:e,reseller:t,isLoading:n,withoutReports:o,userEmail:l,isSuperAdmin:d}){const{toast:f}=useToast(),{Statement:g,CreditLimit:b}=t,[_,S]=React.useState(!1),[R,C]=React.useState(!1),[E,A]=React.useState(!1),[M,I]=React.useState(!1),[j,q]=React.useState(l||""),[Q,te]=React.useState(!1),[F,V]=React.useState((b==null?void 0:b.toString())||""),[ne,{isLoading:ae}]=usePostV4PartnerByApplicationIdAccountResellerCreditLimitMutation(),se=[{label:"0 - 30 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(g==null?void 0:g.Over0)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:Calendar$1},{label:"31 - 45 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(g==null?void 0:g.Over30)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarDays},{label:"45+ Days",value:jsxRuntime.jsx(FormattedNumber,{value:(g==null?void 0:g.Over45)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarRange},{label:"Total",value:jsxRuntime.jsx(FormattedNumber,{value:(g==null?void 0:g.Total)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:DollarSign},{label:"Credit Limit",value:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(FormattedNumber,{value:b||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),d&&jsxRuntime.jsx(Button$1,{size:"icon",variant:"outline",className:"ml-2",onClick:()=>{te(!0),V((b==null?void 0:b.toString())||"")},children:jsxRuntime.jsx(SquarePen,{})})]}),icon:CreditCard}],[Oe]=useLazyGetV4ResellerByRouteResellerIdDocumentAndDocumentNumberPdfQuery(),Ne=async je=>{je?S(!0):C(!0);try{const qe=(await Oe({routeResellerId:e,documentNumber:`ST${e}`})).data;if(!qe)throw new Error("No data received for download.");if(je)window.open(qe);else{const Ve=document.createElement("a");Ve.href=qe,Ve.download=`ST${e}.pdf`,document.body.appendChild(Ve),Ve.click(),Ve.remove()}f({title:"Success",description:"Statement downloaded successfully.",variant:"success"})}catch(Be){console.error("Download Error:",Be),f({title:"Error",description:"An error occurred while downloading the statement. Please try again.",variant:"destructive"})}finally{je?S(!1):C(!1)}},[oe]=usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),$e=async()=>{if(!j||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j)){f({title:"Invalid Email",description:"Please enter a valid email address.",variant:"destructive"});return}A(!0);try{await oe({routeResellerId:e,emailAddress:j}).unwrap(),f({title:"Success",description:`Statement sent to ${j} successfully.`,variant:"success"}),I(!1)}catch(Be){console.error("Send Email Error:",Be),f({title:"Error",description:"An error occurred while sending the statement. Please try again.",variant:"destructive"})}finally{A(!1)}};if(n)return jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(Skeleton,{className:"h-6 w-36"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:[1,2,3].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]},je))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:[1,2].map(je=>jsxRuntime.jsx("div",{className:je===2?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]})},je))})]}),jsxRuntime.jsxs("div",{className:"flex justify-end mt-6 gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-28"})]})]})]});const Ae=!o;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Billing Overview"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:se.slice(0,3).map((je,Be)=>jsxRuntime.jsx(BillingItem,{icon:je.icon,label:je.label,value:je.value},Be))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:se.slice(3).map((je,Be)=>jsxRuntime.jsx("div",{className:Be===1?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsx(BillingItem,{icon:je.icon,label:je.label,value:je.value})},Be))})]}),Ae&&jsxRuntime.jsxs("div",{className:"flex justify-end mt-6 gap-2",children:[jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"outline",size:"icon",onClick:()=>Ne(!0),disabled:_,children:_?jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(Printer,{className:"h-4 w-4"})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Print Statement"})})]})}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"outline",size:"icon",onClick:()=>Ne(!1),disabled:R,children:R?jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(Download,{className:"h-4 w-4"})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Download Statement"})})]})}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"outline",size:"icon",onClick:()=>I(!0),disabled:E,children:E?jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(Mail,{className:"h-4 w-4"})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Email Statement"})})]})}),jsxRuntime.jsx(reactRouterDom.Link,{to:`${window.location.hostname==="dashboard.randmar.io"?"":"https://dashboard.randmar.io"}/${e}/PayInvoice`,target:window.location.hostname==="dashboard.randmar.io"?"_self":"_blank",children:jsxRuntime.jsxs(Button$1,{children:[jsxRuntime.jsx(CreditCard,{className:"mr-2 h-4 w-4"}),"Pay Invoices"]})})]})]})]}),jsxRuntime.jsx(Dialog,{open:M,onOpenChange:I,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Send Statement by Email"}),jsxRuntime.jsx(DialogDescription,{children:"Enter the recipient's email address below. The statement will be sent as a PDF attachment."})]}),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:j,onChange:je=>q(je.target.value),className:"col-span-3",placeholder:"recipient@example.com"})]})}),jsxRuntime.jsx(DialogFooter,{children:jsxRuntime.jsx(Button$1,{type:"submit",onClick:$e,disabled:E||!j,children:E?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Send,{className:"mr-2 h-4 w-4"}),"Send"]})})})]})}),jsxRuntime.jsx(Dialog,{open:Q,onOpenChange:te,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Edit Credit Limit"}),jsxRuntime.jsx(DialogDescription,{children:"Enter the new credit limit for this reseller."})]}),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:"creditLimit",className:"text-right",children:"Amount"}),jsxRuntime.jsx(Input,{id:"creditLimit",type:"number",value:F,onChange:je=>V(je.target.value),className:"col-span-3",placeholder:"0.00"})]})}),jsxRuntime.jsx(DialogFooter,{children:jsxRuntime.jsx(Button$1,{type:"submit",onClick:async()=>{const je=Number(F);if(isNaN(je)){f({title:"Invalid Amount",description:"Please enter a valid number for credit limit.",variant:"destructive"});return}try{await ne({applicationId:e,newValue:je}).unwrap(),te(!1),f({title:"Success",description:"Credit limit updated successfully.",variant:"success"})}catch(Be){console.error("Update Credit Limit Error:",Be),f({title:"Error",description:"Failed to update credit limit. Please try again.",variant:"destructive"})}},disabled:ae,children:ae?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function BillingItem({icon:e,label:t,value:n}){return jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(e,{className:"size-4 text-muted-foreground"}),jsxRuntime.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:t})]}),jsxRuntime.jsx("span",{className:"text-base font-semibold ms-auto",children:n})]})}function ChangePricingTierModal({open:e,setOpen:t,tier:n,onTierChange:o,isLoading:l}){const d=()=>{t(!1)};return jsxRuntime.jsx(Dialog,{open:e,onOpenChange:t,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsx(DialogTitle,{children:"Change Pricing Tier"})}),jsxRuntime.jsxs("div",{className:"grid gap-1.5 py-2",children:[jsxRuntime.jsxs("p",{className:"text-lg text-muted-foreground",children:["Requested Pricing Tier: ",jsxRuntime.jsx("span",{className:"font-bold",children:n})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If your account qualifies, your pricing will update immediately."}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If not, we'll review your request and notify you of the decision."})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:d,disabled:l,children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:o,disabled:l,children:l?"Loading...":`Apply for ${n}`})]})]})})}const getPricingText=e=>e===1?"The Best":e===2?"Fixed 12.5% GP on all items":e===3?"Advantageous":e===4?"Buying Group":e===5?"Cost":e,getShippingText=e=>e==="A"?"Free or Custom":e==="B"?"Fixed $10 anywhere":e==="C"?`Free shipping on $150+ orders to your location,
1196
1196
  $15 for drop shipped orders under $1,500,
1197
- $10 with opportunities under $1,000`:e==="D"?"$15 under $1,500":e==="E"?"Full shipping charges":e,getTermsText=e=>e==="STRIPE"?"Credit card payment":e==="NET30"?"Net 30 days":e,AccountTier=({isSuperAdmin:e,readonly:t,reseller:n,appID:o,isLoading:l})=>{const{toast:d}=useToast(),[f,g]=React.useState(!1),[b,_]=React.useState(""),[S,{isLoading:R}]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),C=je=>je&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[je]||"",E=je=>je&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[je]||"",A=je=>je&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[je]||"",[M,I]=React.useState(C((n==null?void 0:n.Priority)??"")),[j,q]=React.useState(E((n==null?void 0:n.ShippingProfile)??"")),[Q,te]=React.useState(A(n==null?void 0:n.PriceProfile)),F=je=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[je]||je,V=je=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[je]||je,ne=je=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[je]||je;React.useEffect(()=>{I(C((n==null?void 0:n.Priority)??"")),q(E((n==null?void 0:n.ShippingProfile)??"")),te(A(n==null?void 0:n.PriceProfile))},[n]);const ae=async(je,Be,qe,Ve)=>{try{(await S({applicationId:o,fieldName:je,newValue:Be})).error?d({title:"Error",description:Ve,variant:"destructive"}):d({title:"Success",description:qe,variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},se=async je=>{I(je);const Be=F(je);ae("Priority",Be,`Priority updated to ${Be}`,"Failed to update priority")},Oe=async je=>{q(je);const Be=V(je);ae("ShippingProfile",Be,`Shipping profile updated to ${Be}`,"Failed to update shipping profile")},Ne=async je=>{te(je);const Be=ne(je);ae("PriceProfile",Be,`Pricing profile updated to ${Be}`,"Failed to update pricing profile")},oe=async()=>{try{const je=await S({applicationId:o,fieldName:"Tier",newValue:b});je.error?d({title:"Error",description:"Failed to update reseller",variant:"destructive"}):je.data?d({title:"Success",description:`Pricing Tier changed to ${b}`,variant:"success"}):d({title:"Considered",description:"Request being considered",variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}finally{g(!1),_("")}},$e=[{name:"Terms",enabled:n.Priority==="Starter"},{name:"E-Commerce",enabled:n.Priority==="Commercial"},{name:"Commercial",enabled:n.Priority==="E-Commerce"},{name:"Exclusive",enabled:e}],Ae=je=>{_(je),g(!0)};return l?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-16 rounded-full"})]})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsxs("div",{className:"mb-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-56"})]}),jsxRuntime.jsx("div",{className:"grid gap-3",children:[1,2,3].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]})]},je))}),jsxRuntime.jsxs("div",{className:"flex gap-2 mt-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Account Tier"}),jsxRuntime.jsx(Badge,{variant:"secondary",className:"bg-green-100 text-green-700 hover:bg-green-200 text-xs",children:"Active"})]}),jsxRuntime.jsxs(CardContent,{className:"pt-2 px-4 pb-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-3 bg-primary/5 p-4 rounded-lg",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h3",{className:"text-lg font-bold text-primary",children:[(n==null?void 0:n.Priority)||""," Tier"]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Optimized for online retail"})]}),jsxRuntime.jsx(CircleCheck,{className:"h-6 w-6 text-green-600"})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Package2,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Pricing"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground truncate",children:getPricingText(n.PriceProfile||0)})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Truck,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Shipping"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getShippingText(n.ShippingProfile||"").split(".")[0]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Calendar$1,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Payment terms"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getTermsText((n==null?void 0:n.Terms)||"")})]})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[!t&&jsxRuntime.jsx(Button$1,{variant:"outline",className:"flex-1",asChild:!0,children:jsxRuntime.jsxs(reactRouterDom.Link,{to:"https://randmar.io/pricing",target:"_blank",children:[jsxRuntime.jsx(ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),jsxRuntime.jsxs(Popover,{children:[jsxRuntime.jsx(PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{disabled:t,className:t?"hidden":"flex-1",children:["Upgrade Tier ",jsxRuntime.jsx(ChevronRight,{className:"h-3 w-3 ml-1"})]})}),jsxRuntime.jsx(PopoverContent,{className:"w-56 p-2",children:jsxRuntime.jsxs("div",{className:"grid gap-1",children:[jsxRuntime.jsx("h4",{className:"font-medium text-xs mb-1",children:"Select a tier"}),$e.map(je=>jsxRuntime.jsx(Button$1,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!je.enabled,onClick:()=>Ae(je.name),children:je.name},je.name))]})})]})]})]})]}),jsxRuntime.jsx(ChangePricingTierModal,{isLoading:R,open:f,setOpen:g,tier:b,onTierChange:oe}),e&&!t&&jsxRuntime.jsxs(Card,{className:"mt-4",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2 pt-3 px-4",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Admin Configuration"})}),jsxRuntime.jsx(CardContent,{className:"pt-2 px-4 pb-4",children:jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Priority"}),jsxRuntime.jsx(RadioGroup$1,{value:M,onValueChange:se,className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 gap-1",children:[{value:"starter",label:"Starter"},{value:"ecommerce",label:"E-Commerce"},{value:"commercial",label:"Commercial"},{value:"cws",label:"CWS (Basics)"},{value:"novexco",label:"Novexco"},{value:"coopsco",label:"COOPSCO"},{value:"jeancoutu",label:"Jean Coutu"},{value:"exclusive",label:"Exclusive"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`priority-${je.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`priority-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:j,onValueChange:Oe,className:"grid grid-cols-1 @md:grid-cols-2 gap-1",children:[{value:"free",label:"Free (A)"},{value:"fixed",label:"Fixed $10 Shipping (B)"},{value:"dropshipped",label:"$15 for drop shipped (C)"},{value:"under1500",label:"15$ under 1,500 (D)"},{value:"fullcharges",label:"Full shipping charges (E)"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`shipping-${je.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`shipping-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:Q,onValueChange:Ne,className:"grid grid-cols-2 @sm:grid-cols-3 gap-1",children:[{value:"exclusive",label:"Exclusive (1)"},{value:"ecommerce",label:"E-Commerce (2)"},{value:"commercial",label:"Commercial (3)"},{value:"buyinggroup",label:"Buying Group (4)"},{value:"cost",label:"Cost (5)"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`pricing-${je.value}`,className:"h-6 w-6 scale-50 antialiased"}),jsxRuntime.jsx(Label$2,{htmlFor:`pricing-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]})]})})]})]})};function OrderCategories({openOrders:e=[],isLoading:t=!1}){const n=(e==null?void 0:e.filter(M=>M.DocumentType==="Order"))||[],o=(e==null?void 0:e.filter(M=>M.DocumentType==="Shipment"))||[],l=n.filter(M=>M.WarehouseCode!=="3PLE"),d=l.reduce((M,I)=>M+(I.Quantity??0),0),f=l.reduce((M,I)=>M+(I.ExtendedPrice??0),0),g=n.filter(M=>M.WarehouseCode==="3PLE"),b=g.reduce((M,I)=>M+(I.Quantity??0),0),_=g.reduce((M,I)=>M+(I.ExtendedPrice??0),0),S=o.reduce((M,I)=>M+(I.Quantity??0),0),R=o.reduce((M,I)=>M+(I.ExtendedPrice??0),0),C=d+b+S,E=f+_+R,A=[{name:"All",icon:Package,color:"bg-blue-500",orders:C,amount:E},{name:"Processing",icon:RefreshCcw,color:"bg-yellow-500",orders:d,amount:f},{name:"Shipped",icon:Truck,color:"bg-green-500",orders:S,amount:R},{name:"Delayed",icon:CircleAlert,color:"bg-red-500",orders:b,amount:_}];return t?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-40"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(M=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:"bg-gray-200 h-[3px]"}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-12"})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]})]})]})]})},M))})})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Order Categories"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:A.map(M=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:`${M.color} bg-opacity-60 h-[3px]`}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-base",children:M.name}),jsxRuntime.jsx("div",{className:`${M.color} bg-opacity-90 p-2 rounded-full`,children:jsxRuntime.jsx(M.icon,{className:"size-4 shrink-0 text-white"})})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),jsxRuntime.jsx("p",{className:"text-xl font-bold",children:M.orders})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),jsxRuntime.jsx("p",{className:"text-base font-semibold",children:jsxRuntime.jsx(FormattedNumber,{value:M.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},M.name))})})]})}function ReportsSection({isLoading:e,userEmail:t,appID:n}){const{toast:o}=useToast(),[l,{isLoading:d}]=usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[f,{isLoading:g}]=usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[b,{isLoading:_}]=usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[S,{isLoading:R}]=usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[C,{isLoading:E}]=usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[A,{isLoading:M}]=usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[I,j]=React.useState(null),[q,Q]=React.useState(t),[te,F]=React.useState(!1),[V,ne]=React.useState("all"),{data:ae,isLoading:se}=useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:n,withSpecification:!1}),Oe=[{name:"Products",reports:[{id:"Products",title:"Universal Product List",description:"A comprehensive overview of your product list with detailed specifications and pricing information.",icon:Package}]},{name:"Operation Details",reports:[{id:"OpenOrders",title:"Order Details",description:"A detailed report of all your orders and shipments, including status, tracking information, and delivery estimates.",icon:ShoppingCart},{id:"Invoices",title:"Invoices and Credits Report",description:"Detailed overview of your invoices and credits within a specific date range. It also contains reports about additional charges, serial numbers, and other relevant information.",icon:ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:Banknote}]},{name:"Tracking Files",reports:[{id:"AmazonTrackingFile",title:"Amazon Tracking File",description:"Track products sold on Amazon marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing}]}],Ne=async Ae=>{j(Ae),Ae.id==="Products"&&ne("all"),F(!0)},oe=async()=>{if(!(!I||!n))try{switch(I.id){case"Products":{const Ae={routeResellerId:n,emailAddress:q};V&&V!=="all"&&(Ae.manufacturerId=V),await S(Ae).unwrap();break}case"AmazonTrackingFile":await f({routeResellerId:n,emailAddress:q}).unwrap();break;case"WalmartTrackingFile":await l({routeResellerId:n,emailAddress:q}).unwrap();break;case"OpenOrders":await b({routeResellerId:n,emailAddress:q}).unwrap();break;case"Invoices":await C({routeResellerId:n,emailAddress:q}).unwrap();break;case"Statement":await A({routeResellerId:n,emailAddress:q}).unwrap();break;default:throw new Error("invalid report id")}o({title:"Report requested",description:`The ${I.title} will be sent to ${q} shortly.`,variant:"success"}),F(!1)}catch(Ae){console.error("Error requesting report:",Ae),o({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},$e=_||R||g||d||M||E;return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reports"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Product List to your Order Details."})]}),jsxRuntime.jsx(CardContent,{className:"space-y-6",children:e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:[1,2,3].map(Ae=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-48"}),[1,2].map(je=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-9 rounded-full"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})]},je))]},Ae))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:Oe.map(Ae=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:Ae.name}),Ae.reports.map(je=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg hover:bg-gray-100 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-2 rounded-full",children:jsxRuntime.jsx(je.icon,{className:"h-5 w-5 text-primary"})}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("h4",{className:"font-semibold text-sm",children:je.title}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:je.description})]}),jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>Ne(je),children:[jsxRuntime.jsx(Download,{className:"h-4 w-4"}),"Request"]})]},je.id))]},Ae.name))})}),jsxRuntime.jsx(Dialog,{open:te,onOpenChange:F,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsxs(DialogTitle,{children:["Request ",I==null?void 0:I.title]}),jsxRuntime.jsx(DialogDescription,{children:"Enter the email address where you would like to receive the report."})]}),jsxRuntime.jsxs("div",{className:"py-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",value:q,onChange:Ae=>Q(Ae.target.value),placeholder:"your@email.com",className:"mt-2"})]}),(I==null?void 0:I.id)==="Products"&&jsxRuntime.jsxs("div",{className:"py-2",children:[jsxRuntime.jsx(Label$2,{htmlFor:"manufacturer",children:"Manufacturer"}),jsxRuntime.jsxs("select",{id:"manufacturer",className:"mt-2 block w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:V,onChange:Ae=>ne(Ae.target.value),disabled:se,children:[jsxRuntime.jsx("option",{value:"all",children:"All manufacturers"}),!se&&Array.isArray(ae)&&ae.slice().sort((Ae,je)=>(Ae.PublicName||Ae.Name||"").localeCompare(je.PublicName||je.Name||"")).map(Ae=>Ae!=null&&Ae.ManufacturerId?jsxRuntime.jsx("option",{value:Ae.ManufacturerId,children:(Ae.PublicName||Ae.Name||Ae.ManufacturerId)+(Ae.OpenToWork?" (Open to Work)":"")},Ae.ManufacturerId):null)]})]}),jsxRuntime.jsx(DialogDescription,{children:"The report will take around 5 minutes to generate."}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>F(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:oe,disabled:!q||$e,children:$e?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function QualificationBadge({qualification:e}){return!e.QualificationId||e.QualificationId==="Suspended"?null:e.QualificationId==="Do Not Sell"?jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"destructive",children:[jsxRuntime.jsx(X$1,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})}):jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"info",className:e.DefaultOpportunityNumber?"pr-1":"",children:[jsxRuntime.jsx(BadgeCheck,{className:"h-3 w-3 mr-1"}),e.QualificationId,e.DefaultOpportunityNumber&&jsxRuntime.jsx(Badge,{variant:"secondary",size:"sm",className:"ml-1",children:e.DefaultOpportunityNumber})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})})}function SalesChart({statistics:e,mode:t="month",chartHeight:n,loading:o=!1,size:l="default"}){const[d,f]=React.useState([]),[g,b]=React.useState(!1),_=[{name:"dollarVolume",label:"Dollar Volume",color:"var(--primary)",yAxisId:"left",format:"money"},{name:"unitsSold",label:"Units Sold",color:"#888",units:" units",yAxisId:"right",format:"integer"}];return React.useEffect(()=>{if(o||!e){f([]);return}let S=[];if(t==="week"){const R=new Map;e.forEach(C=>{var A;const E=((A=C.Day)==null?void 0:A.toString())||"";if(E.length===8){const M=parseInt(E.substring(0,4),10),I=parseInt(E.substring(4,6),10)-1,j=parseInt(E.substring(6,8),10),q=new Date(M,I,j),Q=new Date(q);Q.setDate(q.getDate()-q.getDay());const te=`${Q.getFullYear()}-${String(Q.getMonth()+1).padStart(2,"0")}-${String(Q.getDate()).padStart(2,"0")}`,F=R.get(te)||{price:0,quantity:0};F.price+=C.ExtendedPrice||0,F.quantity+=C.Quantity||0,R.set(te,F)}}),S=Array.from(R).sort(([C],[E])=>C.localeCompare(E)).map(([C,E])=>({date:`${C.substring(5,7)}/${C.substring(8,10)}`,dollarVolume:E.price,unitsSold:E.quantity}))}else{const R=new Date,C=R.getFullYear(),E=R.getMonth(),A=R.getDate(),M=`${C}-${(E+1).toString().padStart(2,"0")}`,I=Array.from({length:12},(q,Q)=>{const te=new Date(C,E-(11-Q),1);return`${te.getFullYear()}-${(te.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(I.map(q=>[q,{price:0,quantity:0}]));if(e.forEach(q=>{const Q=String(q.Day??0);if(Q.length!==8)return;const te=`${Q.substring(0,4)}-${Q.substring(4,6)}`;j[te]&&(j[te].price+=q.ExtendedPrice??0,j[te].quantity+=q.Quantity??0)}),S=I.map(q=>{const Q=j[q],[te,F]=q.split("-").map(Number);return{date:new Date(te,F-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:Q.price,unitsSold:Q.quantity}}),g){const q=j[M];if(q&&q.price>0&&A>0){const Q=new Date(C,E+1,0).getDate();if(A<Q){const te=q.price/A,F=q.quantity/A,V=te*Q,ne=F*Q,ae=S[S.length-1];ae&&(ae.dollarVolume=V,ae.unitsSold=ne)}}}}f(S)},[e,t,g,o]),o?jsxRuntime.jsx("div",{style:{height:n},children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full rounded-md"})}):d.length===0?jsxRuntime.jsx("div",{style:{height:n},className:"flex items-center justify-center text-muted-foreground",children:"No sales data available."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(AreaChart,{data:d,series:_,height:n,size:l}),l==="default"&&t==="month"&&jsxRuntime.jsxs("div",{className:"mt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Switch,{checked:g,onCheckedChange:b,id:"extrapolate-switch"}),jsxRuntime.jsx(Label$2,{htmlFor:"extrapolate-switch",children:"Extrapolate Current Month"})]}),g&&jsxRuntime.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["* Values for ",new Date().toLocaleString("default",{month:"long"})," are projected estimates."]})]})]})}function PartnerCardHeader({type:e,applicationId:t,publicName:n,name:o,location:l,link:d,linkNewTab:f=!0,children:g}){const[b,_]=React.useState(!1),S=C=>{C.preventDefault(),C.stopPropagation(),navigator.clipboard.writeText(t),_(!0),setTimeout(()=>_(!1),2e3)},R=jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"h-12 w-12 overflow-hidden rounded-md",children:jsxRuntime.jsx(PartnerLogo,{id:t,width:48,height:48},`partner_logo_${t}`)}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-primary",children:e}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"|"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{delayDuration:300,children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex cursor-pointer items-center gap-1",onClick:S,children:[jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:t}),b?jsxRuntime.jsx(Check,{className:"h-3 w-3 text-green-500"}):jsxRuntime.jsx(Copy,{className:"h-3 w-3 text-muted-foreground"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:b?"Copied!":"Copy ID"})})]})})]}),jsxRuntime.jsx("h3",{className:"font-semibold",children:n||"N/A"}),o&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:o}),l&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:l})]})]}),g&&jsxRuntime.jsx("div",{className:"flex flex-col items-end gap-2",children:g})]});return d?jsxRuntime.jsx(reactRouterDom.Link,{to:d,target:f?"_blank":"_self",children:R}):R}function ManufacturerCard({manufacturer:e,link:t,linkNewTab:n=!0,actions:o,mainAction:l,loading:d=!1,appID:f}){var te,F,V;const{toast:g}=useToast(),[b,{isLoading:_}]=usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[S,R]=React.useState(!1),[C,E]=React.useState(""),{data:A}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:f||""},{skip:!f}),M=A==null?void 0:A.IsReseller;if(d||!e)return jsxRuntime.jsxs(Card,{className:"flex flex-col h-full",children:[jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-12 rounded-md"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-24 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-48"})]})]}),jsxRuntime.jsx(Skeleton,{className:"h-16 w-24"})]}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex flex-col space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-16 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-14 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-36"})]})]})]})}),jsxRuntime.jsxs(CardFooter,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-40"})]})]});const I=[e.City,e.Province,e.Country].filter(Boolean),j=I.length>0?I.join(", "):"",q=((te=e.Tags)==null?void 0:te.split(",").map(ne=>ne.trim()).filter(Boolean))||[],Q=async()=>{if(!(!(e!=null&&e.ManufacturerId)||!f||!C))try{await b({routeResellerId:f,emailAddress:C,manufacturerId:e.ManufacturerId}).unwrap(),g({title:"Report requested",description:`The Universal Product List for this manufacturer will be sent to ${C} shortly.`,variant:"success"}),R(!1)}catch(ne){console.error("Error requesting product list:",ne),g({title:"Error",description:"Failed to request product list. Please try again.",variant:"destructive"})}};return jsxRuntime.jsxs(Card,{className:"manufacturer-theme flex flex-col h-full",children:[jsxRuntime.jsx(PartnerCardHeader,{type:"Manufacturer",applicationId:e.ManufacturerId,publicName:e.PublicName,name:e.Name,location:j,link:t,linkNewTab:n,children:jsxRuntime.jsx("div",{className:"flex flex-col items-end gap-2",children:e.SalesStatistics&&e.SalesStatistics.length>0&&jsxRuntime.jsx("div",{className:"h-16 w-24",children:jsxRuntime.jsx(SalesChart,{statistics:e.SalesStatistics,size:"mini"})})})}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(!!((F=e.Qualification)!=null&&F.QualificationId)&&((V=e.Qualification)==null?void 0:V.QualificationId)!=="Suspended"||!!e.OpenToWork||!!e.OnHold&&e.OnHold!==0||q.length>0)&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(QualificationBadge,{qualification:e.Qualification??{}}),!!e.OpenToWork&&jsxRuntime.jsxs(Badge,{variant:"success",children:[jsxRuntime.jsx(HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!e.OnHold&&e.OnHold!==0&&jsxRuntime.jsx(Badge,{variant:"warning",children:"On Hold"}),q.map((ne,ae)=>jsxRuntime.jsx(Badge,{variant:"outline",children:ne},ae))]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[e.Phone&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`tel:${e.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Phone,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.Phone})]}),e.PublicEmail&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`mailto:${e.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Mail,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.PublicEmail})]}),e.Website&&jsxRuntime.jsxs(reactRouterDom.Link,{to:e.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Globe,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.Website})]}),e.CurrencyCode&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(DollarSign,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.CurrencyCode})]})]})]}),e.SalesData&&jsxRuntime.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[jsxRuntime.jsx("strong",{className:"",children:"YTD"}),jsxRuntime.jsx("p",{children:e.SalesData.SalesYearToDay?formatMoney(e.SalesData.SalesYearToDay):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"3 mo."}),jsxRuntime.jsx("p",{children:e.SalesData.SalesLast3Months?formatMoney(e.SalesData.SalesLast3Months):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"30 days"}),jsxRuntime.jsx("p",{children:e.SalesData.SalesLast30Days?formatMoney(e.SalesData.SalesLast30Days):"—"})]})]})}),(o||l||e.PublicResourcesLink||M&&f&&e.ManufacturerId)&&jsxRuntime.jsxs(CardFooter,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[o&&o,M&&f&&e.ManufacturerId&&jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{size:"icon",onClick:()=>R(!0),disabled:_,children:_?jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(Download,{className:"h-4 w-4"})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Email Product List"})})]})}),e.PublicResourcesLink&&jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:e.PublicResourcesLink,target:"_blank",children:jsxRuntime.jsx(Button$1,{size:"icon",children:jsxRuntime.jsx(HardDriveDownload,{className:"h-4 w-4"})})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Public Resources Link"})})]})})]}),l&&jsxRuntime.jsx("div",{children:l})]}),jsxRuntime.jsx(Dialog,{open:S,onOpenChange:R,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Request Universal Product List"}),jsxRuntime.jsx(DialogDescription,{children:"Enter the email address where you would like to receive the report."})]}),jsxRuntime.jsxs("div",{className:"py-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",value:C,onChange:ne=>E(ne.target.value),placeholder:"your@email.com",className:"mt-2"})]}),jsxRuntime.jsx(DialogDescription,{children:"The report will take around 5 minutes to generate."}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>R(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:Q,disabled:!C||_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function ProductInventoryButton({applicationId:e,randmarSku:t,inventory:n,buttonSize:o="default"}){var Oe;const l=React.useRef(null),d=useIntersectionObserver({elementRef:l,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{toast:f}=useToast(),[g,b]=React.useState(!1),[_,S]=React.useState(!1),[R,C]=React.useState(!1),{data:E,isLoading:A,isFetching:M}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:e},{skip:!e||!d}),{data:I,isLoading:j,isFetching:q}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:e,randmarSku:t,withSpecification:!1},{skip:!!n||!d}),[Q]=usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(),te=n??((Oe=I==null?void 0:I.Distribution)==null?void 0:Oe.Inventory);React.useEffect(()=>{b(!1)},[t]);const{inventoryQuantity:F,totalIncomingQuantity:V}=React.useMemo(()=>{if(!te||te.length===0)return{inventoryQuantity:0,totalIncomingQuantity:0};const Ne=te.reduce(($e,Ae)=>$e+(Ae.AvailableQuantity||0),0),oe=te.reduce(($e,Ae)=>$e+(Ae.PurchaseOrderQuantity||0),0);return{inventoryQuantity:Ne,totalIncomingQuantity:oe}},[te]);if(A||M||j||q)return jsxRuntime.jsx("div",{ref:l,children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-36 rounded-md"})});const ae=()=>{R||!(E!=null&&E.IsReseller)||(C(!0),Q({routeResellerId:e??"",randmarSku:t??""}).then(Ne=>{Ne.error||Ne.data===!1?f({title:"Warning",description:"Reorder is pending or requires manual approval. Contact the Randmar team for details.",variant:"warning"}):f({title:"Success",description:"Qualification successfully submitted.",variant:"success"}),S(!1)}).catch(Ne=>{console.error(Ne),f({title:"Error",description:"Error submitting your qualification.",variant:"destructive"})}).finally(()=>{C(!1)}))};if(!te)return jsxRuntime.jsx("div",{ref:l,children:jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{tabIndex:0,children:jsxRuntime.jsxs(Button$1,{disabled:!0,size:o,variant:"outline",className:"text-sm",children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),"No data"]})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"No inventory data could be found for this product."})})]})})});if(E!=null&&E.IsReseller&&F<=0&&V<=0)return jsxRuntime.jsx("div",{ref:l,children:jsxRuntime.jsxs(Dialog,{open:_,onOpenChange:S,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:o,className:"text-sm reseller-theme text-primary",children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),"Request to stock"]})}),jsxRuntime.jsxs(DialogContent,{className:"max-w-md",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsx(DialogTitle,{children:"Request to stock"})}),jsxRuntime.jsx("p",{className:"py-4",children:"Are you sure you want to request this product to be stocked?"}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>S(!1),disabled:R,children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:ae,disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Requesting..."]}):"Confirm"})]})]})]})});const se=F<=0&&V>0;return jsxRuntime.jsx("div",{ref:l,children:jsxRuntime.jsxs(Dialog,{open:g,onOpenChange:b,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:o,className:`text-sm ${se?"manufacturer-theme text-primary":F>0?"text-green-700":"text-red-700"}`,children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),se?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[formatNumber(V)," Incoming"]}):F>0?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[formatNumber(F)," in stock"]}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Out of stock"})]})}),jsxRuntime.jsxs(DialogContent,{className:"max-w-4xl",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsxs(DialogTitle,{className:"flex items-center",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2",size:18}),"Inventory Information"]})}),jsxRuntime.jsx(ProductInventoryGrid,{inventory:te})]})]})})}function OrdersCard({applicationId:e,orders:t=null,loading:n=!1,title:o="Order Details"}){const l=React.useMemo(()=>[{accessorKey:"OrderNumber",header:"Order Number",cell:({row:g})=>g.original.OrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${e}/GeneralDocument/${g.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:g.original.OrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for order ",g.original.OrderNumber]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentNumber",header:"Document Number",cell:({row:g})=>g.original.DocumentNumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentDate",header:"Document Date",cell:({row:g})=>formatYYYYMMDDIntToDateString(g.original.DocumentDate),enableSorting:!0,enableFiltering:!1},{accessorKey:"PONumber",header:"PO Number",cell:({row:g})=>g.original.PONumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseCode",header:"Warehouse",cell:({row:g})=>g.original.WarehouseCode??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"MPN",header:"MPN",cell:({row:g})=>g.original.MPN?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${e}/Product/${g.original.MPN}`,className:"font-medium text-primary hover:underline",children:g.original.MPN})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for MPN ",g.original.MPN]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:g})=>g.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!1},{accessorKey:"ShipToName",header:"Name",cell:({row:g})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:g.original.ShipToName??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:g})=>g.original.UnitPrice?formatMoney(g.original.UnitPrice):"N/A",enableSorting:!0,enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:g})=>jsxRuntime.jsx("div",{className:"flex space-x-2",children:jsxRuntime.jsx(ProductInventoryButton,{applicationId:e,randmarSku:g.original.RandmarSKU??"",buttonSize:"sm"})})}],[e]),d=React.useMemo(()=>{const g={};if(t){const b=Array.from(new Set(t.map(A=>A.WarehouseCode).filter(A=>A!=null)));g.WarehouseCode=b;const _=Array.from(new Set(t.map(A=>A.ShipToName).filter(A=>A!=null)));g.ShipToName=_;const S=Array.from(new Set(t.map(A=>A.DocumentNumber).filter(A=>A!=null)));g.DocumentNumber=S;const R=Array.from(new Set(t.map(A=>A.OrderNumber).filter(A=>A!=null)));g.OrderNumber=R;const C=Array.from(new Set(t.map(A=>A.PONumber).filter(A=>A!=null)));g.PONumber=C;const E=Array.from(new Set(t.map(A=>A.MPN).filter(A=>A!=null)));g.MPN=E}return g},[t]),f=t||[];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-10 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-10 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:o})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:l,data:f,uniqueValues:d})})]})}function ResellerOverview({appID:e,reseller:t,readonly:n,userEmail:o,isSuperAdmin:l,withoutReports:d=!1}){var q,Q,te,F;const{data:f,isLoading:g,isError:b}=useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:e??"",withSpecification:!0},{skip:!!t}),[_,S]=React.useState({publicInfo:{hasUnsavedChanges:!1}}),R=React.useCallback(()=>n?!1:_.publicInfo.hasUnsavedChanges,[n,_]),C=React.useCallback((V,ne)=>{S(ae=>{var se;return((se=ae[V])==null?void 0:se.hasUnsavedChanges)!==ne.hasUnsavedChanges?{...ae,[V]:ne}:ae})},[]),{NavigationGuardDialog:E}=useRouterNavigationGuard(R),A=t??f,M=!n||!!(A!=null&&A.Statement)&&(A.Statement.Total??0)>0,I=(A==null?void 0:A.QualifiedManufacturers)??[],j=(A==null?void 0:A.Qualifications)??[];return jsxRuntime.jsxs("div",{className:"@container",children:[b?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your reseller information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:(A==null?void 0:A.FiscalYearMonthStart)||1,salesData:A==null?void 0:A.SalesData,isLoading:g}),jsxRuntime.jsxs("div",{className:"grid @lg:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChartCard,{statistics:(A==null?void 0:A.SalesStatistics)??[],loading:g}),jsxRuntime.jsx(OrderCategories,{openOrders:(A==null?void 0:A.ActiveOrderDetails)??[],isLoading:g}),M&&jsxRuntime.jsx(BillingCard,{appID:e,reseller:A||{},withoutReports:d,isLoading:g,userEmail:o,isSuperAdmin:l}),jsxRuntime.jsx(PublicInfo,{reseller:A||{},appID:e??"",isLoading:g,readonly:n,onUnsavedChanges:V=>C("publicInfo",{hasUnsavedChanges:V})}),jsxRuntime.jsx(AccountTier,{isSuperAdmin:l,readonly:n,reseller:A||{},appID:e??"",isLoading:g})]}),g||I.length>0?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Manufacturers you are qualified for"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid @lg:grid-cols-2 gap-4",children:g?Array.from({length:2}).map((V,ne)=>jsxRuntime.jsx(ManufacturerCard,{loading:!0},ne)):I.map(V=>jsxRuntime.jsx(ManufacturerCard,{manufacturer:V,link:`https://dashboard.randmar.io/${e}/Partner/${V.ManufacturerId}`},V.ManufacturerId))})})]}):j.length>0&&jsxRuntime.jsx(ResellerQualificationsCard,{qualifications:j}),(((q=A==null?void 0:A.Opportunities)==null?void 0:q.length)??0)>0&&jsxRuntime.jsx(OpportunitiesTable,{applicationId:e,opportunities:A==null?void 0:A.Opportunities,loading:g}),(((Q=A==null?void 0:A.ActiveOrderDetails)==null?void 0:Q.length)??0)>0&&jsxRuntime.jsx(OrdersCard,{applicationId:e,title:"Active Orders",orders:A==null?void 0:A.ActiveOrderDetails,loading:g}),(((te=A==null?void 0:A.CompletedOrderDetails)==null?void 0:te.length)??0)>0&&jsxRuntime.jsx(OrdersCard,{applicationId:e,title:"Completed Orders",orders:A==null?void 0:A.CompletedOrderDetails,loading:g}),(((F=A==null?void 0:A.Returns)==null?void 0:F.length)??0)>0&&jsxRuntime.jsx(ReturnsTable,{applicationId:e,returns:A==null?void 0:A.Returns,loading:g}),!d&&jsxRuntime.jsx(ReportsSection,{appID:e,userEmail:o,isLoading:g})]}),jsxRuntime.jsx(E,{})]})}const alertVariants=cva("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",success:"border-green-500/50 bg-green-50 text-green-700 dark:border-green-500 dark:bg-green-950 dark:text-green-400 [&>svg]:text-green-500",warning:"border-yellow-500/50 bg-yellow-50 text-yellow-700 dark:border-yellow-500 dark:bg-yellow-950 dark:text-yellow-400 [&>svg]:text-yellow-500",info:"border-blue-500/50 bg-blue-50 text-blue-700 dark:border-blue-500 dark:bg-blue-950 dark:text-blue-400 [&>svg]:text-blue-500"}},defaultVariants:{variant:"default"}}),Alert=React__namespace.forwardRef(({className:e,variant:t,...n},o)=>jsxRuntime.jsx("div",{ref:o,role:"alert",className:cn(alertVariants({variant:t}),e),...n}));Alert.displayName="Alert";const AlertTitle=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx("h5",{ref:n,className:cn("mb-1 font-medium leading-none tracking-tight",e),...t}));AlertTitle.displayName="AlertTitle";const AlertDescription=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx("div",{ref:n,className:cn("text-sm [&_p]:leading-relaxed",e),...t}));AlertDescription.displayName="AlertDescription";/**
1197
+ $10 with opportunities under $1,000`:e==="D"?"$15 under $1,500":e==="E"?"Full shipping charges":e,getTermsText=e=>e==="STRIPE"?"Credit card payment":e==="NET30"?"Net 30 days":e,AccountTier=({isSuperAdmin:e,readonly:t,reseller:n,appID:o,isLoading:l})=>{const{toast:d}=useToast(),[f,g]=React.useState(!1),[b,_]=React.useState(""),[S,{isLoading:R}]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),C=je=>je&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[je]||"",E=je=>je&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[je]||"",A=je=>je&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[je]||"",[M,I]=React.useState(C((n==null?void 0:n.Priority)??"")),[j,q]=React.useState(E((n==null?void 0:n.ShippingProfile)??"")),[Q,te]=React.useState(A(n==null?void 0:n.PriceProfile)),F=je=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[je]||je,V=je=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[je]||je,ne=je=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[je]||je;React.useEffect(()=>{I(C((n==null?void 0:n.Priority)??"")),q(E((n==null?void 0:n.ShippingProfile)??"")),te(A(n==null?void 0:n.PriceProfile))},[n]);const ae=async(je,Be,qe,Ve)=>{try{(await S({applicationId:o,fieldName:je,newValue:Be})).error?d({title:"Error",description:Ve,variant:"destructive"}):d({title:"Success",description:qe,variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},se=async je=>{I(je);const Be=F(je);ae("Priority",Be,`Priority updated to ${Be}`,"Failed to update priority")},Oe=async je=>{q(je);const Be=V(je);ae("ShippingProfile",Be,`Shipping profile updated to ${Be}`,"Failed to update shipping profile")},Ne=async je=>{te(je);const Be=ne(je);ae("PriceProfile",Be,`Pricing profile updated to ${Be}`,"Failed to update pricing profile")},oe=async()=>{try{const je=await S({applicationId:o,fieldName:"Tier",newValue:b});je.error?d({title:"Error",description:"Failed to update reseller",variant:"destructive"}):je.data?d({title:"Success",description:`Pricing Tier changed to ${b}`,variant:"success"}):d({title:"Considered",description:"Request being considered",variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}finally{g(!1),_("")}},$e=[{name:"Terms",enabled:n.Priority==="Starter"},{name:"E-Commerce",enabled:n.Priority==="Commercial"},{name:"Commercial",enabled:n.Priority==="E-Commerce"},{name:"Exclusive",enabled:e}],Ae=je=>{_(je),g(!0)};return l?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-16 rounded-full"})]})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsxs("div",{className:"mb-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-56"})]}),jsxRuntime.jsx("div",{className:"grid gap-3",children:[1,2,3].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]})]},je))}),jsxRuntime.jsxs("div",{className:"flex gap-2 mt-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Account Tier"}),jsxRuntime.jsx(Badge,{variant:"secondary",className:"bg-green-100 text-green-700 hover:bg-green-200 text-xs",children:"Active"})]}),jsxRuntime.jsxs(CardContent,{className:"pt-2 px-4 pb-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-3 bg-primary/5 p-4 rounded-lg",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h3",{className:"text-lg font-bold text-primary",children:[(n==null?void 0:n.Priority)||""," Tier"]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Optimized for online retail"})]}),jsxRuntime.jsx(CircleCheck,{className:"h-6 w-6 text-green-600"})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Package2,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Pricing"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground truncate",children:getPricingText(n.PriceProfile||0)})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Truck,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Shipping"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getShippingText(n.ShippingProfile||"").split(".")[0]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Calendar$1,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Payment terms"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getTermsText((n==null?void 0:n.Terms)||"")})]})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[!t&&jsxRuntime.jsx(Button$1,{variant:"outline",className:"flex-1",asChild:!0,children:jsxRuntime.jsxs(reactRouterDom.Link,{to:"https://randmar.io/pricing",target:"_blank",children:[jsxRuntime.jsx(ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),jsxRuntime.jsxs(Popover,{children:[jsxRuntime.jsx(PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{disabled:t,className:t?"hidden":"flex-1",children:["Upgrade Tier ",jsxRuntime.jsx(ChevronRight,{className:"h-3 w-3 ml-1"})]})}),jsxRuntime.jsx(PopoverContent,{className:"w-56 p-2",children:jsxRuntime.jsxs("div",{className:"grid gap-1",children:[jsxRuntime.jsx("h4",{className:"font-medium text-xs mb-1",children:"Select a tier"}),$e.map(je=>jsxRuntime.jsx(Button$1,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!je.enabled,onClick:()=>Ae(je.name),children:je.name},je.name))]})})]})]})]})]}),jsxRuntime.jsx(ChangePricingTierModal,{isLoading:R,open:f,setOpen:g,tier:b,onTierChange:oe}),e&&!t&&jsxRuntime.jsxs(Card,{className:"mt-4",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2 pt-3 px-4",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Admin Configuration"})}),jsxRuntime.jsx(CardContent,{className:"pt-2 px-4 pb-4",children:jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Priority"}),jsxRuntime.jsx(RadioGroup$1,{value:M,onValueChange:se,className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 gap-1",children:[{value:"starter",label:"Starter"},{value:"ecommerce",label:"E-Commerce"},{value:"commercial",label:"Commercial"},{value:"cws",label:"CWS (Basics)"},{value:"novexco",label:"Novexco"},{value:"coopsco",label:"COOPSCO"},{value:"jeancoutu",label:"Jean Coutu"},{value:"exclusive",label:"Exclusive"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`priority-${je.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`priority-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:j,onValueChange:Oe,className:"grid grid-cols-1 @md:grid-cols-2 gap-1",children:[{value:"free",label:"Free (A)"},{value:"fixed",label:"Fixed $10 Shipping (B)"},{value:"dropshipped",label:"$15 for drop shipped (C)"},{value:"under1500",label:"15$ under 1,500 (D)"},{value:"fullcharges",label:"Full shipping charges (E)"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`shipping-${je.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`shipping-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:Q,onValueChange:Ne,className:"grid grid-cols-2 @sm:grid-cols-3 gap-1",children:[{value:"exclusive",label:"Exclusive (1)"},{value:"ecommerce",label:"E-Commerce (2)"},{value:"commercial",label:"Commercial (3)"},{value:"buyinggroup",label:"Buying Group (4)"},{value:"cost",label:"Cost (5)"}].map(je=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:je.value,id:`pricing-${je.value}`,className:"h-6 w-6 scale-50 antialiased"}),jsxRuntime.jsx(Label$2,{htmlFor:`pricing-${je.value}`,className:"cursor-pointer text-xs",children:je.label})]},je.value))})]})]})})]})]})};function OrderCategories({openOrders:e=[],isLoading:t=!1}){const n=(e==null?void 0:e.filter(M=>M.DocumentType==="Order"))||[],o=(e==null?void 0:e.filter(M=>M.DocumentType==="Shipment"))||[],l=n.filter(M=>M.WarehouseCode!=="3PLE"),d=l.reduce((M,I)=>M+(I.Quantity??0),0),f=l.reduce((M,I)=>M+(I.ExtendedPrice??0),0),g=n.filter(M=>M.WarehouseCode==="3PLE"),b=g.reduce((M,I)=>M+(I.Quantity??0),0),_=g.reduce((M,I)=>M+(I.ExtendedPrice??0),0),S=o.reduce((M,I)=>M+(I.Quantity??0),0),R=o.reduce((M,I)=>M+(I.ExtendedPrice??0),0),C=d+b+S,E=f+_+R,A=[{name:"All",icon:Package,color:"bg-blue-500",orders:C,amount:E},{name:"Processing",icon:RefreshCcw,color:"bg-yellow-500",orders:d,amount:f},{name:"Shipped",icon:Truck,color:"bg-green-500",orders:S,amount:R},{name:"Delayed",icon:CircleAlert,color:"bg-red-500",orders:b,amount:_}];return t?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-40"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(M=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:"bg-gray-200 h-[3px]"}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-12"})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]})]})]})]})},M))})})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Order Categories"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:A.map(M=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:`${M.color} bg-opacity-60 h-[3px]`}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-base",children:M.name}),jsxRuntime.jsx("div",{className:`${M.color} bg-opacity-90 p-2 rounded-full`,children:jsxRuntime.jsx(M.icon,{className:"size-4 shrink-0 text-white"})})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),jsxRuntime.jsx("p",{className:"text-xl font-bold",children:M.orders})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),jsxRuntime.jsx("p",{className:"text-base font-semibold",children:jsxRuntime.jsx(FormattedNumber,{value:M.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},M.name))})})]})}function ReportsSection({isLoading:e,userEmail:t,appID:n}){const{toast:o}=useToast(),[l,{isLoading:d}]=usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[f,{isLoading:g}]=usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[b,{isLoading:_}]=usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[S,{isLoading:R}]=usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[C,{isLoading:E}]=usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[A,{isLoading:M}]=usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[I,j]=React.useState(null),[q,Q]=React.useState(t),[te,F]=React.useState(!1),[V,ne]=React.useState("all"),{data:ae,isLoading:se}=useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:n,withSpecification:!1}),Oe=[{name:"Products",reports:[{id:"Products",title:"Universal Product List",description:"A comprehensive overview of your product list with detailed specifications and pricing information.",icon:Package}]},{name:"Operation Details",reports:[{id:"OpenOrders",title:"Order Details",description:"A detailed report of all your orders and shipments, including status, tracking information, and delivery estimates.",icon:ShoppingCart},{id:"Invoices",title:"Invoices and Credits Report",description:"Detailed overview of your invoices and credits within a specific date range. It also contains reports about additional charges, serial numbers, and other relevant information.",icon:ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:Banknote}]},{name:"Tracking Files",reports:[{id:"AmazonTrackingFile",title:"Amazon Tracking File",description:"Track products sold on Amazon marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing}]}],Ne=async Ae=>{j(Ae),Ae.id==="Products"&&ne("all"),F(!0)},oe=async()=>{if(!(!I||!n))try{switch(I.id){case"Products":{const Ae={routeResellerId:n,emailAddress:q};V&&V!=="all"&&(Ae.manufacturerId=V),await S(Ae).unwrap();break}case"AmazonTrackingFile":await f({routeResellerId:n,emailAddress:q}).unwrap();break;case"WalmartTrackingFile":await l({routeResellerId:n,emailAddress:q}).unwrap();break;case"OpenOrders":await b({routeResellerId:n,emailAddress:q}).unwrap();break;case"Invoices":await C({routeResellerId:n,emailAddress:q}).unwrap();break;case"Statement":await A({routeResellerId:n,emailAddress:q}).unwrap();break;default:throw new Error("invalid report id")}o({title:"Report requested",description:`The ${I.title} will be sent to ${q} shortly.`,variant:"success"}),F(!1)}catch(Ae){console.error("Error requesting report:",Ae),o({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},$e=_||R||g||d||M||E;return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reports"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Product List to your Order Details."})]}),jsxRuntime.jsx(CardContent,{className:"space-y-6",children:e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:[1,2,3].map(Ae=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-48"}),[1,2].map(je=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-9 rounded-full"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})]},je))]},Ae))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:Oe.map(Ae=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:Ae.name}),Ae.reports.map(je=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg hover:bg-gray-100 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-2 rounded-full",children:jsxRuntime.jsx(je.icon,{className:"h-5 w-5 text-primary"})}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("h4",{className:"font-semibold text-sm",children:je.title}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:je.description})]}),jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>Ne(je),children:[jsxRuntime.jsx(Download,{className:"h-4 w-4"}),"Request"]})]},je.id))]},Ae.name))})}),jsxRuntime.jsx(Dialog,{open:te,onOpenChange:F,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsxs(DialogTitle,{children:["Request ",I==null?void 0:I.title]}),jsxRuntime.jsx(DialogDescription,{children:"Enter the email address where you would like to receive the report."})]}),jsxRuntime.jsxs("div",{className:"py-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",value:q,onChange:Ae=>Q(Ae.target.value),placeholder:"your@email.com",className:"mt-2"})]}),(I==null?void 0:I.id)==="Products"&&jsxRuntime.jsxs("div",{className:"py-2",children:[jsxRuntime.jsx(Label$2,{htmlFor:"manufacturer",children:"Manufacturer"}),jsxRuntime.jsxs("select",{id:"manufacturer",className:"mt-2 block w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:V,onChange:Ae=>ne(Ae.target.value),disabled:se,children:[jsxRuntime.jsx("option",{value:"all",children:"All manufacturers"}),!se&&Array.isArray(ae)&&ae.slice().sort((Ae,je)=>(Ae.PublicName||Ae.Name||"").localeCompare(je.PublicName||je.Name||"")).map(Ae=>Ae!=null&&Ae.ManufacturerId?jsxRuntime.jsx("option",{value:Ae.ManufacturerId,children:(Ae.PublicName||Ae.Name||Ae.ManufacturerId)+(Ae.OpenToWork?" (Open to Work)":"")},Ae.ManufacturerId):null)]})]}),jsxRuntime.jsx(DialogDescription,{children:"The report will take around 5 minutes to generate."}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>F(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:oe,disabled:!q||$e,children:$e?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function QualificationBadge({qualification:e}){return!e.QualificationId||e.QualificationId==="Suspended"?null:e.QualificationId==="Do Not Sell"?jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"destructive",children:[jsxRuntime.jsx(X$1,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})}):jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"info",className:e.DefaultOpportunityNumber?"pr-1":"",children:[jsxRuntime.jsx(BadgeCheck,{className:"h-3 w-3 mr-1"}),e.QualificationId,e.DefaultOpportunityNumber&&jsxRuntime.jsx(Badge,{variant:"secondary",size:"sm",className:"ml-1",children:e.DefaultOpportunityNumber})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})})}function SalesChart({statistics:e,mode:t="month",chartHeight:n,loading:o=!1,size:l="default"}){const[d,f]=React.useState([]),[g,b]=React.useState(!1),_=[{name:"dollarVolume",label:"Dollar Volume",color:"var(--primary)",yAxisId:"left",format:"money"},{name:"unitsSold",label:"Units Sold",color:"#888",units:" units",yAxisId:"right",format:"integer"}];return React.useEffect(()=>{if(o||!e){f([]);return}let S=[];if(t==="week"){const R=new Map;e.forEach(C=>{var A;const E=((A=C.Day)==null?void 0:A.toString())||"";if(E.length===8){const M=parseInt(E.substring(0,4),10),I=parseInt(E.substring(4,6),10)-1,j=parseInt(E.substring(6,8),10),q=new Date(M,I,j),Q=new Date(q);Q.setDate(q.getDate()-q.getDay());const te=`${Q.getFullYear()}-${String(Q.getMonth()+1).padStart(2,"0")}-${String(Q.getDate()).padStart(2,"0")}`,F=R.get(te)||{price:0,quantity:0};F.price+=C.ExtendedPrice||0,F.quantity+=C.Quantity||0,R.set(te,F)}}),S=Array.from(R).sort(([C],[E])=>C.localeCompare(E)).map(([C,E])=>({date:`${C.substring(5,7)}/${C.substring(8,10)}`,dollarVolume:E.price,unitsSold:E.quantity}))}else{const R=new Date,C=R.getFullYear(),E=R.getMonth(),A=R.getDate(),M=`${C}-${(E+1).toString().padStart(2,"0")}`,I=Array.from({length:12},(q,Q)=>{const te=new Date(C,E-(11-Q),1);return`${te.getFullYear()}-${(te.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(I.map(q=>[q,{price:0,quantity:0}]));if(e.forEach(q=>{const Q=String(q.Day??0);if(Q.length!==8)return;const te=`${Q.substring(0,4)}-${Q.substring(4,6)}`;j[te]&&(j[te].price+=q.ExtendedPrice??0,j[te].quantity+=q.Quantity??0)}),S=I.map(q=>{const Q=j[q],[te,F]=q.split("-").map(Number);return{date:new Date(te,F-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:Q.price,unitsSold:Q.quantity}}),g){const q=j[M];if(q&&q.price>0&&A>0){const Q=new Date(C,E+1,0).getDate();if(A<Q){const te=q.price/A,F=q.quantity/A,V=te*Q,ne=F*Q,ae=S[S.length-1];ae&&(ae.dollarVolume=V,ae.unitsSold=ne)}}}}f(S)},[e,t,g,o]),o?jsxRuntime.jsx("div",{style:{height:n},children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full rounded-md"})}):d.length===0?jsxRuntime.jsx("div",{style:{height:n},className:"flex items-center justify-center text-muted-foreground",children:"No sales data available."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(AreaChart,{data:d,series:_,height:n,size:l}),l==="default"&&t==="month"&&jsxRuntime.jsxs("div",{className:"mt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Switch,{checked:g,onCheckedChange:b,id:"extrapolate-switch"}),jsxRuntime.jsx(Label$2,{htmlFor:"extrapolate-switch",children:"Extrapolate Current Month"})]}),g&&jsxRuntime.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["* Values for ",new Date().toLocaleString("default",{month:"long"})," are projected estimates."]})]})]})}function PartnerCardHeader({type:e,applicationId:t,publicName:n,name:o,location:l,link:d,linkNewTab:f=!0,children:g}){const[b,_]=React.useState(!1),S=C=>{C.preventDefault(),C.stopPropagation(),navigator.clipboard.writeText(t),_(!0),setTimeout(()=>_(!1),2e3)},R=jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"h-12 w-12 overflow-hidden rounded-md",children:jsxRuntime.jsx(PartnerLogo,{id:t,width:48,height:48},`partner_logo_${t}`)}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-primary",children:e}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"|"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{delayDuration:300,children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex cursor-pointer items-center gap-1",onClick:S,children:[jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:t}),b?jsxRuntime.jsx(Check,{className:"h-3 w-3 text-green-500"}):jsxRuntime.jsx(Copy,{className:"h-3 w-3 text-muted-foreground"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:b?"Copied!":"Copy ID"})})]})})]}),jsxRuntime.jsx("h3",{className:"font-semibold",children:n||"N/A"}),o&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:o}),l&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:l})]})]}),g&&jsxRuntime.jsx("div",{className:"flex flex-col items-end gap-2",children:g})]});return d?jsxRuntime.jsx(reactRouterDom.Link,{to:d,target:f?"_blank":"_self",children:R}):R}function ManufacturerCard({manufacturer:e,link:t,linkNewTab:n=!0,actions:o,mainAction:l,loading:d=!1,appID:f}){var te,F,V;const{toast:g}=useToast(),[b,{isLoading:_}]=usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[S,R]=React.useState(!1),[C,E]=React.useState(""),{data:A}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:f||""},{skip:!f}),M=A==null?void 0:A.IsReseller;if(d||!e)return jsxRuntime.jsxs(Card,{className:"flex flex-col h-full",children:[jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-12 rounded-md"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-24 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-48"})]})]}),jsxRuntime.jsx(Skeleton,{className:"h-16 w-24"})]}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex flex-col space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-16 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-14 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-36"})]})]})]})}),jsxRuntime.jsxs(CardFooter,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-40"})]})]});const I=[e.City,e.Province,e.Country].filter(Boolean),j=I.length>0?I.join(", "):"",q=((te=e.Tags)==null?void 0:te.split(",").map(ne=>ne.trim()).filter(Boolean))||[],Q=async()=>{if(!(!(e!=null&&e.ManufacturerId)||!f||!C))try{await b({routeResellerId:f,emailAddress:C,manufacturerId:e.ManufacturerId}).unwrap(),g({title:"Report requested",description:`The Universal Product List for this manufacturer will be sent to ${C} shortly.`,variant:"success"}),R(!1)}catch(ne){console.error("Error requesting product list:",ne),g({title:"Error",description:"Failed to request product list. Please try again.",variant:"destructive"})}};return jsxRuntime.jsxs(Card,{className:"manufacturer-theme flex flex-col h-full",children:[jsxRuntime.jsx(PartnerCardHeader,{type:"Manufacturer",applicationId:e.ManufacturerId,publicName:e.PublicName,name:e.Name,location:j,link:t,linkNewTab:n,children:jsxRuntime.jsx("div",{className:"flex flex-col items-end gap-2",children:e.SalesStatistics&&e.SalesStatistics.length>0&&jsxRuntime.jsx("div",{className:"h-16 w-24",children:jsxRuntime.jsx(SalesChart,{statistics:e.SalesStatistics,size:"mini"})})})}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(!!((F=e.Qualification)!=null&&F.QualificationId)&&((V=e.Qualification)==null?void 0:V.QualificationId)!=="Suspended"||!!e.OpenToWork||!!e.OnHold&&e.OnHold!==0||q.length>0)&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(QualificationBadge,{qualification:e.Qualification??{}}),!!e.OpenToWork&&jsxRuntime.jsxs(Badge,{variant:"success",children:[jsxRuntime.jsx(HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!e.OnHold&&e.OnHold!==0&&jsxRuntime.jsx(Badge,{variant:"warning",children:"On Hold"}),q.map((ne,ae)=>jsxRuntime.jsx(Badge,{variant:"outline",children:ne},ae))]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[e.Phone&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`tel:${e.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Phone,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.Phone})]}),e.PublicEmail&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`mailto:${e.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Mail,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.PublicEmail})]}),e.Website&&jsxRuntime.jsxs(reactRouterDom.Link,{to:e.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Globe,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.Website})]}),e.CurrencyCode&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(DollarSign,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:e.CurrencyCode})]})]})]}),e.SalesData&&jsxRuntime.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[jsxRuntime.jsx("strong",{className:"",children:"YTD"}),jsxRuntime.jsx("p",{children:e.SalesData.SalesYearToDay?formatMoney(e.SalesData.SalesYearToDay):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"3 mo."}),jsxRuntime.jsx("p",{children:e.SalesData.SalesLast3Months?formatMoney(e.SalesData.SalesLast3Months):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"30 days"}),jsxRuntime.jsx("p",{children:e.SalesData.SalesLast30Days?formatMoney(e.SalesData.SalesLast30Days):"—"})]})]})}),(o||l||e.PublicResourcesLink||M&&f&&e.ManufacturerId)&&jsxRuntime.jsxs(CardFooter,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[o&&o,M&&f&&e.ManufacturerId&&jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{size:"icon",onClick:()=>R(!0),disabled:_,children:_?jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(Download,{className:"h-4 w-4"})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Email Product List"})})]})}),e.PublicResourcesLink&&jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:e.PublicResourcesLink,target:"_blank",children:jsxRuntime.jsx(Button$1,{size:"icon",children:jsxRuntime.jsx(HardDriveDownload,{className:"h-4 w-4"})})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Public Resources Link"})})]})})]}),l&&jsxRuntime.jsx("div",{children:l})]}),jsxRuntime.jsx(Dialog,{open:S,onOpenChange:R,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Request Universal Product List"}),jsxRuntime.jsx(DialogDescription,{children:"Enter the email address where you would like to receive the report."})]}),jsxRuntime.jsxs("div",{className:"py-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",value:C,onChange:ne=>E(ne.target.value),placeholder:"your@email.com",className:"mt-2"})]}),jsxRuntime.jsx(DialogDescription,{children:"The report will take around 5 minutes to generate."}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>R(!1),children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:Q,disabled:!C||_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function ProductInventoryButton({applicationId:e,randmarSku:t,inventory:n,buttonSize:o="default",buttonClassName:l}){var Ne;const d=React.useRef(null),f=useIntersectionObserver({elementRef:d,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{toast:g}=useToast(),[b,_]=React.useState(!1),[S,R]=React.useState(!1),[C,E]=React.useState(!1),{data:A,isLoading:M,isFetching:I}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:e},{skip:!e||!f}),{data:j,isLoading:q,isFetching:Q}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:e,randmarSku:t,withSpecification:!1},{skip:!!n||!f}),[te]=usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(),F=n??((Ne=j==null?void 0:j.Distribution)==null?void 0:Ne.Inventory);React.useEffect(()=>{_(!1)},[t]);const{inventoryQuantity:V,totalIncomingQuantity:ne}=React.useMemo(()=>{if(!F||F.length===0)return{inventoryQuantity:0,totalIncomingQuantity:0};const oe=F.reduce((Ae,je)=>Ae+(je.AvailableQuantity||0),0),$e=F.reduce((Ae,je)=>Ae+(je.PurchaseOrderQuantity||0),0);return{inventoryQuantity:oe,totalIncomingQuantity:$e}},[F]);if(M||I||q||Q)return jsxRuntime.jsx("div",{ref:d,children:jsxRuntime.jsx(Skeleton,{className:cn("h-10 w-36 rounded-md",l)})});const se=()=>{C||!(A!=null&&A.IsReseller)||(E(!0),te({routeResellerId:e??"",randmarSku:t??""}).then(oe=>{oe.error||oe.data===!1?g({title:"Warning",description:"Reorder is pending or requires manual approval. Contact the Randmar team for details.",variant:"warning"}):g({title:"Success",description:"Qualification successfully submitted.",variant:"success"}),R(!1)}).catch(oe=>{console.error(oe),g({title:"Error",description:"Error submitting your qualification.",variant:"destructive"})}).finally(()=>{E(!1)}))};if(!F)return jsxRuntime.jsx("div",{ref:d,children:jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{tabIndex:0,children:jsxRuntime.jsxs(Button$1,{disabled:!0,size:o,variant:"outline",className:cn("text-sm",l),children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),"No data"]})})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"No inventory data could be found for this product."})})]})})});if(A!=null&&A.IsReseller&&V<=0&&ne<=0)return jsxRuntime.jsx("div",{ref:d,children:jsxRuntime.jsxs(Dialog,{open:S,onOpenChange:R,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:o,className:cn("text-sm reseller-theme text-primary",l),children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),"Request to stock"]})}),jsxRuntime.jsxs(DialogContent,{className:"max-w-md",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsx(DialogTitle,{children:"Request to stock"})}),jsxRuntime.jsx("p",{className:"py-4",children:"Are you sure you want to request this product to be stocked?"}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>R(!1),disabled:C,children:"Cancel"}),jsxRuntime.jsx(Button$1,{onClick:se,disabled:C,children:C?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Requesting..."]}):"Confirm"})]})]})]})});const Oe=V<=0&&ne>0;return jsxRuntime.jsx("div",{ref:d,children:jsxRuntime.jsxs(Dialog,{open:b,onOpenChange:_,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:o,className:cn("text-sm",Oe?"manufacturer-theme text-primary":V>0?"text-green-700":"text-red-700",l),children:[jsxRuntime.jsx(Warehouse,{size:"16",className:"mr-2"}),Oe?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[formatNumber(ne)," Incoming"]}):V>0?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[formatNumber(V)," in stock"]}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Out of stock"})]})}),jsxRuntime.jsxs(DialogContent,{className:"max-w-4xl",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsxs(DialogTitle,{className:"flex items-center",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2",size:18}),"Inventory Information"]})}),jsxRuntime.jsx(ProductInventoryGrid,{inventory:F})]})]})})}function OrdersCard({applicationId:e,orders:t=null,loading:n=!1,title:o="Order Details"}){const l=React.useMemo(()=>[{accessorKey:"OrderNumber",header:"Order Number",cell:({row:g})=>g.original.OrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${e}/GeneralDocument/${g.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:g.original.OrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for order ",g.original.OrderNumber]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentNumber",header:"Document Number",cell:({row:g})=>g.original.DocumentNumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentDate",header:"Document Date",cell:({row:g})=>formatYYYYMMDDIntToDateString(g.original.DocumentDate),enableSorting:!0,enableFiltering:!1},{accessorKey:"PONumber",header:"PO Number",cell:({row:g})=>g.original.PONumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseCode",header:"Warehouse",cell:({row:g})=>g.original.WarehouseCode??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"MPN",header:"MPN",cell:({row:g})=>g.original.MPN?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${e}/Product/${g.original.MPN}`,className:"font-medium text-primary hover:underline",children:g.original.MPN})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for MPN ",g.original.MPN]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:g})=>g.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!1},{accessorKey:"ShipToName",header:"Name",cell:({row:g})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:g.original.ShipToName??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:g})=>g.original.UnitPrice?formatMoney(g.original.UnitPrice):"N/A",enableSorting:!0,enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:g})=>jsxRuntime.jsx("div",{className:"flex space-x-2",children:jsxRuntime.jsx(ProductInventoryButton,{applicationId:e,randmarSku:g.original.RandmarSKU??"",buttonSize:"sm"})})}],[e]),d=React.useMemo(()=>{const g={};if(t){const b=Array.from(new Set(t.map(A=>A.WarehouseCode).filter(A=>A!=null)));g.WarehouseCode=b;const _=Array.from(new Set(t.map(A=>A.ShipToName).filter(A=>A!=null)));g.ShipToName=_;const S=Array.from(new Set(t.map(A=>A.DocumentNumber).filter(A=>A!=null)));g.DocumentNumber=S;const R=Array.from(new Set(t.map(A=>A.OrderNumber).filter(A=>A!=null)));g.OrderNumber=R;const C=Array.from(new Set(t.map(A=>A.PONumber).filter(A=>A!=null)));g.PONumber=C;const E=Array.from(new Set(t.map(A=>A.MPN).filter(A=>A!=null)));g.MPN=E}return g},[t]),f=t||[];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-10 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-10 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:o})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:l,data:f,uniqueValues:d})})]})}function ResellerOverview({appID:e,reseller:t,readonly:n,userEmail:o,isSuperAdmin:l,withoutReports:d=!1}){var q,Q,te,F;const{data:f,isLoading:g,isError:b}=useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:e??"",withSpecification:!0},{skip:!!t}),[_,S]=React.useState({publicInfo:{hasUnsavedChanges:!1}}),R=React.useCallback(()=>n?!1:_.publicInfo.hasUnsavedChanges,[n,_]),C=React.useCallback((V,ne)=>{S(ae=>{var se;return((se=ae[V])==null?void 0:se.hasUnsavedChanges)!==ne.hasUnsavedChanges?{...ae,[V]:ne}:ae})},[]),{NavigationGuardDialog:E}=useRouterNavigationGuard(R),A=t??f,M=!n||!!(A!=null&&A.Statement)&&(A.Statement.Total??0)>0,I=(A==null?void 0:A.QualifiedManufacturers)??[],j=(A==null?void 0:A.Qualifications)??[];return jsxRuntime.jsxs("div",{className:"@container",children:[b?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your reseller information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:(A==null?void 0:A.FiscalYearMonthStart)||1,salesData:A==null?void 0:A.SalesData,isLoading:g}),jsxRuntime.jsxs("div",{className:"grid @lg:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChartCard,{statistics:(A==null?void 0:A.SalesStatistics)??[],loading:g}),jsxRuntime.jsx(OrderCategories,{openOrders:(A==null?void 0:A.ActiveOrderDetails)??[],isLoading:g}),M&&jsxRuntime.jsx(BillingCard,{appID:e,reseller:A||{},withoutReports:d,isLoading:g,userEmail:o,isSuperAdmin:l}),jsxRuntime.jsx(PublicInfo,{reseller:A||{},appID:e??"",isLoading:g,readonly:n,onUnsavedChanges:V=>C("publicInfo",{hasUnsavedChanges:V})}),jsxRuntime.jsx(AccountTier,{isSuperAdmin:l,readonly:n,reseller:A||{},appID:e??"",isLoading:g})]}),g||I.length>0?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Manufacturers you are qualified for"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid @lg:grid-cols-2 gap-4",children:g?Array.from({length:2}).map((V,ne)=>jsxRuntime.jsx(ManufacturerCard,{loading:!0},ne)):I.map(V=>jsxRuntime.jsx(ManufacturerCard,{manufacturer:V,link:`https://dashboard.randmar.io/${e}/Partner/${V.ManufacturerId}`},V.ManufacturerId))})})]}):j.length>0&&jsxRuntime.jsx(ResellerQualificationsCard,{qualifications:j}),(((q=A==null?void 0:A.Opportunities)==null?void 0:q.length)??0)>0&&jsxRuntime.jsx(OpportunitiesTable,{applicationId:e,opportunities:A==null?void 0:A.Opportunities,loading:g}),(((Q=A==null?void 0:A.ActiveOrderDetails)==null?void 0:Q.length)??0)>0&&jsxRuntime.jsx(OrdersCard,{applicationId:e,title:"Active Orders",orders:A==null?void 0:A.ActiveOrderDetails,loading:g}),(((te=A==null?void 0:A.CompletedOrderDetails)==null?void 0:te.length)??0)>0&&jsxRuntime.jsx(OrdersCard,{applicationId:e,title:"Completed Orders",orders:A==null?void 0:A.CompletedOrderDetails,loading:g}),(((F=A==null?void 0:A.Returns)==null?void 0:F.length)??0)>0&&jsxRuntime.jsx(ReturnsTable,{applicationId:e,returns:A==null?void 0:A.Returns,loading:g}),!d&&jsxRuntime.jsx(ReportsSection,{appID:e,userEmail:o,isLoading:g})]}),jsxRuntime.jsx(E,{})]})}const alertVariants=cva("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",success:"border-green-500/50 bg-green-50 text-green-700 dark:border-green-500 dark:bg-green-950 dark:text-green-400 [&>svg]:text-green-500",warning:"border-yellow-500/50 bg-yellow-50 text-yellow-700 dark:border-yellow-500 dark:bg-yellow-950 dark:text-yellow-400 [&>svg]:text-yellow-500",info:"border-blue-500/50 bg-blue-50 text-blue-700 dark:border-blue-500 dark:bg-blue-950 dark:text-blue-400 [&>svg]:text-blue-500"}},defaultVariants:{variant:"default"}}),Alert=React__namespace.forwardRef(({className:e,variant:t,...n},o)=>jsxRuntime.jsx("div",{ref:o,role:"alert",className:cn(alertVariants({variant:t}),e),...n}));Alert.displayName="Alert";const AlertTitle=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx("h5",{ref:n,className:cn("mb-1 font-medium leading-none tracking-tight",e),...t}));AlertTitle.displayName="AlertTitle";const AlertDescription=React__namespace.forwardRef(({className:e,...t},n)=>jsxRuntime.jsx("div",{ref:n,className:cn("text-sm [&_p]:leading-relaxed",e),...t}));AlertDescription.displayName="AlertDescription";/**
1198
1198
  * table-core
1199
1199
  *
1200
1200
  * Copyright (c) TanStack
@@ -1237,7 +1237,7 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
1237
1237
  `;break;default:e+=String.fromCharCode(n);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),t=this.pos}else++this.pos}},pp.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\":++this.pos;break;case"$":if(this.input[this.pos+1]!=="{")break;case"`":return this.finishToken(types$1.invalidTemplate,this.input.slice(this.start,this.pos));case"\r":this.input[this.pos+1]===`
1238
1238
  `&&++this.pos;case`
1239
1239
  `:case"\u2028":case"\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")},pp.readEscapedChar=function(e){var t=this.input.charCodeAt(++this.pos);switch(++this.pos,t){case 110:return`
1240
- `;case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return codePointToString(this.readCodePoint());case 116:return" ";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),e){var n=this.pos-1;this.invalidStringToken(n,"Invalid escape sequence in template string")}default:if(t>=48&&t<=55){var o=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],l=parseInt(o,8);return l>255&&(o=o.slice(0,-1),l=parseInt(o,8)),this.pos+=o.length-1,t=this.input.charCodeAt(this.pos),(o!=="0"||t===56||t===57)&&(this.strict||e)&&this.invalidStringToken(this.pos-1-o.length,e?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(l)}return isNewLine(t)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(t)}},pp.readHexChar=function(e){var t=this.pos,n=this.readInt(16,e);return n===null&&this.invalidStringToken(t,"Bad character escape sequence"),n},pp.readWord1=function(){this.containsEsc=!1;for(var e="",t=!0,n=this.pos,o=this.options.ecmaVersion>=6;this.pos<this.input.length;){var l=this.fullCharCodeAtPos();if(isIdentifierChar(l,o))this.pos+=l<=65535?1:2;else if(l===92){this.containsEsc=!0,e+=this.input.slice(n,this.pos);var d=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos;var f=this.readCodePoint();(t?isIdentifierStart:isIdentifierChar)(f,o)||this.invalidStringToken(d,"Invalid Unicode escape"),e+=codePointToString(f),n=this.pos}else break;t=!1}return e+this.input.slice(n,this.pos)},pp.readWord=function(){var e=this.readWord1(),t=types$1.name;return this.keywords.test(e)&&(t=keywords[e]),this.finishToken(t,e)};var version="8.12.1";Parser.acorn={Parser,version,defaultOptions,Position,SourceLocation,getLineInfo,Node:Node$3,TokenType,tokTypes:types$1,keywordTypes:keywords,TokContext,tokContexts:types,isIdentifierChar,isIdentifierStart,Token,isNewLine,lineBreak,lineBreakG,nonASCIIwhitespace};var AcornJSX=__toESM(require_acorn_jsx()),attributeNames_default={acceptcharset:"acceptCharset",accesskey:"accessKey",allowfullscreen:"allowFullScreen",autocapitalize:"autoCapitalize",autocomplete:"autoComplete",autofocus:"autoFocus",autoplay:"autoPlay",cellpadding:"cellPadding",cellspacing:"cellSpacing",charset:"charSet",class:"className",colspan:"colSpan",contenteditable:"contentEditable",crossorigin:"crossOrigin",datetime:"dateTime",enctype:"encType",for:"htmlFor",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",frameborder:"frameBorder",hreflang:"hrefLang",httpequiv:"httpEquiv",inputmode:"inputMode",keyparams:"keyParams",keytype:"keyType",marginheight:"marginHeight",marginwidth:"marginWidth",maxlength:"maxLength",mediagroup:"mediaGroup",minlength:"minLength",novalidate:"noValidate",radiogroup:"radioGroup",readonly:"readOnly",referrerpolicy:"referrerPolicy",rowspan:"rowSpan",spellcheck:"spellCheck",srcdoc:"srcDoc",srclang:"srcLang",srcset:"srcSet",tabindex:"tabIndex",usemap:"useMap"},VOID_ELEMENTS=["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],NO_WHITESPACE=["table","tbody","tfoot","thead","tr"];function canHaveChildren(e){return VOID_ELEMENTS.indexOf(e.toLowerCase())===-1}function canHaveWhitespace(e){return NO_WHITESPACE.indexOf(e.toLowerCase())!==-1}class NullishShortCircuit extends Error{constructor(t="Nullish value encountered"){super(t),this.name="NullishShortCircuit"}}var hash=(e="",t=16)=>{const n=String(e);let o=0;return n.split("").forEach(l=>{o=(o<<5)-o+l.charCodeAt(0),o&=o}),Math.abs(o).toString(t)},randomHash=()=>hash(Math.random().toString()),camelCase=e=>e.replace(/([A-Z])([A-Z])/g,"$1 $2").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[^a-zA-Z\u00C0-\u00ff]/g," ").toLowerCase().split(" ").filter(t=>t).map((t,n)=>n>0?t[0].toUpperCase()+t.slice(1):t).join(""),parseStyle=e=>{switch(typeof e){case"string":return e.split(";").filter(t=>t).reduce((t,n)=>{const o=n.slice(0,n.indexOf(":")).trim(),l=n.slice(n.indexOf(":")+1).trim();return{...t,[camelCase(o)]:l}},{});case"object":return e;default:return}},pathToArrayPath=e=>e==null||e===""?[]:e.split("."),resolveArrayPath=(e,t)=>{const[n,...o]=t;if(!(e==null||n==null))return o.length===0?e[n]:resolveArrayPath(e[n],o)},resolvePath=(e,t)=>resolveArrayPath(e,pathToArrayPath(t));function handleNaN(e){return Number.isNaN(e)?"NaN":e}class JsxParser extends React.Component{constructor(){super(...arguments);en(this,"ParsedChildren",null);zn(this,fn,n=>{const o=Parser.extend(AcornJSX.default({autoCloseVoidElements:this.props.autoCloseVoidElements})),l=`<root>${n}</root>`;let d=[];try{return d=o.parse(l,{ecmaVersion:"latest"}),d=d.body[0].expression.children||[],d.map(f=>on(this,rn).call(this,f)).filter(Boolean)}catch(f){return this.props.showWarnings&&console.warn(f),this.props.onError&&this.props.onError(f),this.props.renderError?this.props.renderError({error:String(f)}):null}});zn(this,rn,(n,o)=>{var l,d;switch(n.type){case"JSXAttribute":return n.value===null?!0:on(this,rn).call(this,n.value,o);case"JSXElement":case"JSXFragment":return on(this,Qn).call(this,n,o);case"JSXExpressionContainer":return on(this,rn).call(this,n.expression,o);case"JSXText":const f=this.props.disableKeyGeneration?void 0:randomHash();return this.props.disableFragments?n.value:React.createElement(React.Fragment,{key:f},n.value);case"ArrayExpression":return n.elements.map(A=>on(this,rn).call(this,A,o));case"BinaryExpression":const g=on(this,rn).call(this,n.left,o),b=on(this,rn).call(this,n.right,o);let _;switch(n.operator){case"-":_=g-b;break;case"!=":_=g!=b;break;case"!==":_=g!==b;break;case"*":_=g*b;break;case"**":_=g**b;break;case"/":_=g/b;break;case"%":_=g%b;break;case"+":_=g+b;break;case"<":_=g<b;break;case"<=":_=g<=b;break;case"==":_=g==b;break;case"===":_=g===b;break;case">":_=g>b;break;case">=":_=g>=b;break;default:this.props.onError(new Error(`Unsupported binary operator: ${n.operator}`));return}return handleNaN(_);case"CallExpression":const S=on(this,rn).call(this,n.callee,o);if(S===void 0){if(n.optional)throw new NullishShortCircuit;this.props.onError(new Error(`The expression '${n.callee}' could not be resolved, resulting in an undefined return value.`));return}return S(...n.arguments.map(A=>on(this,rn).call(this,A,o)));case"ConditionalExpression":return on(this,rn).call(this,n.test,o)?on(this,rn).call(this,n.consequent,o):on(this,rn).call(this,n.alternate,o);case"ExpressionStatement":return on(this,rn).call(this,n.expression,o);case"Identifier":return n.name==="Infinity"?1/0:n.name==="-Infinity"?-1/0:n.name==="NaN"?NaN:o&&n.name in o?handleNaN(o[n.name]):handleNaN((this.props.bindings||{})[n.name]);case"Literal":return n.value;case"LogicalExpression":const R=on(this,rn).call(this,n.left,o);return n.operator==="||"&&R?R:n.operator==="&&"&&R||n.operator==="||"&&!R?on(this,rn).call(this,n.right,o):!1;case"MemberExpression":return on(this,ar).call(this,n,o);case"ChainExpression":return on(this,ir).call(this,n,o);case"ObjectExpression":const C={};return n.properties.forEach(A=>{C[A.key.name||A.key.value]=on(this,rn).call(this,A.value,o)}),C;case"TemplateElement":return n.value.cooked;case"TemplateLiteral":return[...n.expressions,...n.quasis].sort((A,M)=>A.start<M.start?-1:1).map(A=>on(this,rn).call(this,A,o)).join("");case"UnaryExpression":const E=on(this,rn).call(this,n.argument,o);switch(n.operator){case"+":return+E;case"-":return-E;case"!":return!E;case"~":return~E;case"typeof":return typeof E}return;case"ArrowFunctionExpression":return(n.async||n.generator)&&((d=(l=this.props).onError)==null||d.call(l,new Error("Async and generator arrow functions are not supported."))),(...A)=>{const M={...o};return n.params.forEach((I,j)=>{M[I.name]=A[j]}),on(this,rn).call(this,n.body,M)};default:this.props.onError(new Error(`The expression type '${n.type}' is not supported.`));return}});zn(this,ir,(n,o)=>{try{return on(this,rn).call(this,n.expression,o)}catch(l){if(l instanceof NullishShortCircuit)return;throw l}});zn(this,ar,(n,o)=>{const l=on(this,rn).call(this,n.object,o);let d;if(n.computed)d=on(this,rn).call(this,n.property,o);else if(n.property.type==="Identifier")d=n.property.name;else{this.props.onError(new Error("Only simple MemberExpressions are supported."));return}if(l==null&&n.optional)throw new NullishShortCircuit;let f;try{f=l[d]}catch{this.props.onError(new Error(`The property '${d}' could not be resolved on the object '${l}'.`));return}return typeof f=="function"?f.bind(l):f});zn(this,Wn,n=>n.type==="JSXIdentifier"?n.name:`${on(this,Wn).call(this,n.object)}.${on(this,Wn).call(this,n.property)}`);zn(this,Qn,(n,o)=>{const{allowUnknownElements:l,components:d,componentsOnly:f,onError:g}=this.props,{children:b=[]}=n,_=n.type==="JSXElement"?n.openingElement:n.openingFragment,{attributes:S=[]}=_,R=n.type==="JSXElement"?on(this,Wn).call(this,_.name):"",C=(this.props.blacklistedAttrs||[]).map(Q=>Q instanceof RegExp?Q:new RegExp(Q,"i")),E=(this.props.blacklistedTags||[]).map(Q=>Q.trim().toLowerCase()).filter(Boolean);if(/^(html|head|body)$/i.test(R))return b.map(Q=>on(this,Qn).call(this,Q,o));const A=R.trim().toLowerCase();if(E.indexOf(A)!==-1)return g(new Error(`The tag <${R}> is blacklisted, and will not be rendered.`)),null;if(R!==""&&!resolvePath(d,R)){if(f)return g(new Error(`The component <${R}> is unrecognized, and will not be rendered.`)),this.props.renderUnrecognized(R);if(!l&&document.createElement(R)instanceof HTMLUnknownElement)return g(new Error(`The tag <${R}> is unrecognized in this browser, and will not be rendered.`)),this.props.renderUnrecognized(R)}let M,I=n.type==="JSXElement"?resolvePath(d,R):React.Fragment;if(I||canHaveChildren(R)){if(M=b.map(te=>on(this,rn).call(this,te,o)),R.includes(".")){const F=R.split(".").reduce((V,ne)=>V?V[ne]:d==null?void 0:d[ne],null);F&&(I=F)}!I&&!canHaveWhitespace(R)&&(M=M.filter(te=>typeof te!="string"||!/^\s*$/.test(te)));const Q=M.find(te=>typeof te=="function");M.length===0?M=void 0:Q?M=Q:M.length===1?[M]=M:M.length>1&&!this.props.disableKeyGeneration&&(M=M.map((te,F)=>te!=null&&te.type&&!(te!=null&&te.key)?{...te,key:te.key||F}:te))}const j={key:this.props.disableKeyGeneration?void 0:randomHash()};S.forEach(Q=>{if(Q.type==="JSXAttribute"){const te=Q.name.name,F=attributeNames_default[te]||te,V=on(this,rn).call(this,Q,o);C.filter(ae=>ae.test(F)).length===0&&(j[F]=V)}else if(Q.type==="JSXSpreadAttribute"&&Q.argument.type==="Identifier"||Q.argument.type==="MemberExpression"){const te=on(this,rn).call(this,Q.argument,o);typeof te=="object"&&Object.keys(te).forEach(F=>{const V=attributeNames_default[F]||F;C.filter(ae=>ae.test(V)).length===0&&(j[V]=te[F])})}}),typeof j.style=="string"&&(j.style=parseStyle(j.style));const q=R.toLowerCase();return q==="option"&&(M=M.props.children),React.createElement(I||q,j,M)})}render(){const n=(this.props.jsx||"").trim().replace(/<!DOCTYPE([^>]*)>/g,"");this.ParsedChildren=on(this,fn).call(this,n);const o=[...new Set(["jsx-parser",...String(this.props.className).split(" ")])].filter(Boolean).join(" ");return this.props.renderInWrapper?React.createElement("div",{className:o},this.ParsedChildren):this.ParsedChildren}}fn=new WeakMap,rn=new WeakMap,ir=new WeakMap,ar=new WeakMap,Wn=new WeakMap,Qn=new WeakMap,en(JsxParser,"displayName","JsxParser"),en(JsxParser,"defaultProps",{allowUnknownElements:!0,autoCloseVoidElements:!1,bindings:{},blacklistedAttrs:[/^on.+/i],blacklistedTags:["script"],className:"",components:{},componentsOnly:!1,disableFragments:!1,disableKeyGeneration:!1,jsx:"",onError:()=>{},showWarnings:!1,renderError:void 0,renderInWrapper:!0,renderUnrecognized:()=>null});var source_default=JsxParser;const CountryFlag=({countryCode:e,className:t=""})=>{const[n,o]=React.useState(null),[l,d]=React.useState(!1);return React.useEffect(()=>{if(!e)return;const g=`https://purecatamphetamine.github.io/country-flag-icons/3x2/${e.toUpperCase()}.svg`;fetch(g,{method:"HEAD"}).then(b=>{b.ok?(o(g),d(!1)):d(!0)}).catch(()=>{d(!0)})},[e]),l||!n?jsxRuntime.jsx("span",{className:t,children:e}):jsxRuntime.jsx("img",{src:n,alt:`${e} flag`,className:`inline-block ${t}`,style:{width:"24px",height:"auto"}})};function ProductCard({applicationId:e,product:t,viewProductLink:n,defaultOpportunityNumber:o="",onAddToCart:l,addingToCart:d=!1,shopifyHostname:f,customAction:g=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var $t,rt,Rt,dt,It,Mt,Ct,Ke,Ye;const b=reactRouterDom.useNavigate(),{toast:_}=useToast(),[S,R]=React.useState(1),[C,E]=React.useState(null),[A,M]=React.useState(0),[I,j]=React.useState(!1),[q]=usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[Q,te]=React.useState(!1),[F,V]=React.useState(null),[ne,ae]=React.useState("idle"),[se,Oe]=React.useState(null),[Ne]=useLazyGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery(),oe=(($t=t==null?void 0:t.Distribution)==null?void 0:$t.Cost)||0,$e=((rt=t==null?void 0:t.Distribution)==null?void 0:rt.RegularPrice)||0,Ae=((Rt=t==null?void 0:t.Distribution)==null?void 0:Rt.Price)||0,je=!!(e&&(t!=null&&t.RandmarSKU));React.useEffect(()=>{R(1),E(null),M(0)},[t==null?void 0:t.RandmarSKU]),React.useEffect(()=>{var Ze;if(t&&o){const ct=(Ze=t.Opportunities)==null?void 0:Ze.find(mt=>mt.BidNumber==o);ct&&Be(ct)&&E(ct)}},[t,o]),React.useEffect(()=>{if(!t)return;const Ze=C!=null&&C.Price?C.Price:Ae;M($e>0?Math.round(($e-Ze)/$e*100):0)},[t,C,Ae,$e]),React.useEffect(()=>{d||R(1)},[d]),React.useEffect(()=>{if(!Q){V(null),ae("idle"),Oe(null);return}if(!e||!(t!=null&&t.RandmarSKU)){ae("error"),Oe("Missing identifiers to load performance data.");return}let Ze=!1;const ct=t.RandmarSKU;return(async()=>{ae("summary"),Oe(null);try{const ft=await Ne({routeApplicationId:e,randmarSku:ct,withSpecification:!1});if(Ze)return;if("error"in ft&&ft.error)throw ft.error;V(ft.data??null),ae("detailed");const yt=await Ne({routeApplicationId:e,randmarSku:ct,withSpecification:!0});if(Ze)return;if("error"in yt&&yt.error)throw yt.error;V(yt.data??ft.data??null),ae("complete")}catch(ft){if(Ze)return;console.error("Failed to load performance data for product modal",ft),ae("error"),Oe("We couldn't load the performance details. Please try again.")}})(),()=>{Ze=!0}},[e,Ne,Q,t==null?void 0:t.RandmarSKU]);const Be=Ze=>{if(Ze.Active!==!0)return!1;const ct=new Date().toISOString().split("T")[0];return!(Ze.EndDate&&Ze.EndDate.split("T")[0]<ct||Ze.StartDate&&Ze.StartDate.split("T")[0]>ct)},qe=Ze=>Ze>=90?{label:"Top 10% Bestseller",color:"text-purple-950",bgColor:"bg-purple-200"}:Ze>=75?{label:"Bestseller",color:"text-blue-700",bgColor:"bg-blue-50"}:Ze>=33?{label:"Popular",color:"text-green-700",bgColor:"bg-green-50"}:{label:"Rising",color:"text-gray-700",bgColor:"bg-white"},Ve=ne!=="complete"&&ne!=="error",Le=ne==="summary"?40:ne==="detailed"?80:10,He=(F==null?void 0:F.SalesStatistics)??[],We=Ve?[]:He,ze=(F==null?void 0:F.RandmarTitle)??(t==null?void 0:t.RandmarTitle)??(t==null?void 0:t.RandmarSKU)??"this product",Xe=(F==null?void 0:F.RandmarSKU)??(t==null?void 0:t.RandmarSKU);if(!t)return jsxRuntime.jsx(Card,{children:jsxRuntime.jsxs(CardContent,{className:"p-6",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx("div",{className:"h-10 w-24 flex items-center justify-end ml-4",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded-md"})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-20 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-24 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-28 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"flex gap-6",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-6 flex-1",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:jsxRuntime.jsx("div",{className:"w-60 h-40",children:jsxRuntime.jsx(Skeleton,{className:"w-full h-full rounded-lg"})})})]}),jsxRuntime.jsxs("div",{className:"flex gap-6 mt-4",children:[jsxRuntime.jsx("div",{className:"flex flex-1",children:jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-24 mb-3"}),jsxRuntime.jsx(Skeleton,{className:"h-16 w-full rounded-md"})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-32 rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24 mt-4"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-6 mt-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-start gap-1 mb-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 flex-1 rounded-md"})]})]})]})});const nt=(t==null?void 0:t.Opportunities)||[],Je=nt.length>0,st=()=>{if(S==null){R(1);return}S>1&&R(S-1)},et=()=>{if(S==null){R(1);return}R(S+1)},at=Ze=>{const ct=Number.parseInt(Ze.target.value,10);if(!isNaN(ct)&&ct>0){R(ct);return}R(void 0)},tt=()=>{(S==null||S<1)&&R(1)},ot=Ze=>{try{return new Date(Ze).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(ct){return console.error(ct),Ze.split("T")[0]||"N/A"}},lt=()=>{typeof l<"u"&&l({quantity:S??1,bidNumber:(C==null?void 0:C.BidNumber)??null})},Ge=()=>{I||!f||(j(!0),q({routeResellerId:e??"",randmarSku:t.RandmarSKU??"",shopifyHostName:f}).then(Ze=>{if(Ze.error){console.error("Error syncing to Shopify:",Ze.error),_({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"});return}_({title:"Product synced",description:"Product synced to Shopify successfully",variant:"success"})}).catch(Ze=>{console.error("Error syncing to Shopify:",Ze),_({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"})}).finally(()=>{j(!1)}))};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Card,{className:"w-full hover:shadow-lg transition-shadow @container",children:jsxRuntime.jsxs(CardContent,{className:"p-6",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-3",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-xl",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex items-center justify-end ml-4 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40},`partner_logo_${t.ManufacturerId}`)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col @[36rem]:flex-row gap-6",children:[jsxRuntime.jsxs("div",{className:"flex-1 @[36rem]:order-1 order-2 flex flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center justify-center @[36rem]:items-start @[36rem]:justify-start",children:[t.State&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.State==="Active"?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(Check,{size:"12",className:"mr-1.5"})," ",t.State]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.SerialNumber?"bg-green-50 text-green-700 hover:bg-green-50":"bg-yellow-50 text-yellow-700 hover:bg-yellow-50"}`,children:[jsxRuntime.jsx(QrCode,{size:"12",className:"mr-1.5"})," ",t.SerialNumber?"Serialized":"Unserialized"]}),t.TransparencyCode&&jsxRuntime.jsxs(Badge,{variant:"outline",className:"rounded-full px-3 bg-green-50 text-green-700 hover:bg-green-50",children:[jsxRuntime.jsx(CircleDashed,{size:"12",className:"mr-1.5"})," Transparency Code"]}),t.AvailableToBuy!==void 0&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.AvailableToBuy?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(ShoppingCart,{size:"12",className:"mr-1.5"})," ",t.AvailableToBuy?"Available":"Unavailable"]}),t.ManufacturerCategory!==void 0&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${(dt=t.ManufacturerCategory)!=null&&dt.QualificationRequired?"bg-blue-50 text-blue-700 hover:bg-blue-50":"bg-neutral-50 text-neutral-700 hover:bg-neutral-50"}`,children:[jsxRuntime.jsx(ShieldCheck,{size:"12",className:"mr-1.5"})," ",(It=t.ManufacturerCategory)!=null&&It.QualificationRequired?"Qualified Only":"Available to all"]}),t.ManufacturerId&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.AutoUpdate?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(RefreshCw,{size:"12",className:"mr-1.5"})," ",t.AutoUpdate?`Automatic Reorder (${t.MasterCarton})`:"Manually Reorders"]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.BodyHTML&&t.Title&&t.MAP?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(Store,{size:"12",className:"mr-1.5"})," ",t.BodyHTML&&t.Title&&t.MAP?"Shopify Ready":"Not Shopify Ready"]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-4 flex-1",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"MPN"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.MPN||"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"UPC"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.UPC||"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"Unit Weight"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.UnitWeight?`${formatNumber(t.UnitWeight)} lbs`:"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"text-sm text-muted-foreground",children:["MAP",jsxRuntime.jsx("span",{className:"text-primary",children:" / "}),"MSRP"]}),jsxRuntime.jsxs("div",{className:"font-medium",children:[t.MAP?formatMoney(t.MAP):"N/A",jsxRuntime.jsx("span",{className:"text-primary",children:" / "}),t.MSRP?formatMoney(t.MSRP):"N/A"]})]}),!!t.OverallPercentileRank&&!!t.ManufacturerPercentileRank&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"Bestseller Status"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{children:"Global: "}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Badge,{variant:"outline",className:`rounded-full px-3 w-fit ${qe(t.OverallPercentileRank).bgColor} ${qe(t.OverallPercentileRank).color} hover:${qe(t.OverallPercentileRank).bgColor}`,children:qe(t.OverallPercentileRank).label})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["Percentile Rank: ",t.OverallPercentileRank]})})]})})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{children:[t.ManufacturerName,": "]}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Badge,{variant:"outline",className:`rounded-full px-3 w-fit ${qe(t.ManufacturerPercentileRank).bgColor} ${qe(t.ManufacturerPercentileRank).color} hover:${qe(t.ManufacturerPercentileRank).bgColor}`,children:qe(t.ManufacturerPercentileRank).label})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["Percentile Rank: ",t.ManufacturerPercentileRank]})})]})})]})]})]}),t.CountryCodeOfOrigin&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"Origin"}),jsxRuntime.jsxs("div",{className:"font-medium flex items-center",children:[jsxRuntime.jsx(CountryFlag,{countryCode:t.CountryCodeOfOrigin,className:"mr-2"}),t.CountryCodeOfOrigin]})]})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col @[36rem]:order-2 order-1 items-center",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""},`product_image_${t.RandmarSKU}`)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col @[36rem]:flex-row gap-6 mt-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-row @[36rem]:flex-col gap-4 justify-center @[36rem]:justify-start @[36rem]:order-2 order-1",children:[n&&jsxRuntime.jsx(reactRouterDom.Link,{to:n,children:jsxRuntime.jsxs(Button$1,{variant:"outline",className:"h-11 px-4 text-sm font-medium justify-start",children:[jsxRuntime.jsx(Eye,{className:"mr-2"}),"View Product"]})}),jsxRuntime.jsx(ProductInventoryButton,{applicationId:e??"",randmarSku:t.RandmarSKU??"",inventory:(Mt=t.Distribution)==null?void 0:Mt.Inventory})]}),jsxRuntime.jsx("div",{className:"flex flex-1 @[36rem]:order-1 order-2",children:Je&&t.Distribution&&jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:"You have "+nt.length+(nt.length>1?" opportunities":" opportunity")+" for this product:"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1",children:nt.map((Ze,ct)=>Be(Ze)?jsxRuntime.jsxs("div",{className:`flex justify-between items-center rounded-lg transition-colors py-2 px-4 border border-muted cursor-pointer ${Ze.BidNumber==(C==null?void 0:C.BidNumber)?"bg-purple-100 border-2 border-purple-900":"bg-white border-1 border-purple-600 hover:bg-purple-200"}`,onClick:()=>{E(Ze.BidNumber!==(C==null?void 0:C.BidNumber)?Ze:null)},children:[jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium text-sm",children:Ze.Opportunity}),jsxRuntime.jsx("span",{className:"text-xs text-neutral-900",children:Ze.BidNumber})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{className:"font-semibold",children:formatMoney(Ze.Price??0)}),Ze.Rebate&&Ze.Rebate>0&&jsxRuntime.jsxs("span",{className:"text-xs text-green-600",children:["Rebate: ",formatMoney(Ze.Rebate)]}),Ze.EndDate&&jsxRuntime.jsxs("span",{className:"text-xs text-neutral-600",children:["Ends: ",ot(Ze.EndDate)]})]})]},ct):jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-purple-100 border border-muted cursor-pointer !bg-neutral-50 hover:bg-neutral-100",onClick:()=>{Ze.BidNumber&&b(`/${e}/Opportunity/${Ze.ManufacturerId}/${Ze.BidNumber}`)},children:[jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium text-sm",children:Ze.Opportunity}),jsxRuntime.jsxs("span",{className:"text-xs text-neutral-900",children:[Ze.BidNumber," ",jsxRuntime.jsx(Badge,{variant:"outline",className:"text-xs mx-1 h-5 bg-gray-100",children:"Currently unavailable"})]})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{className:"font-semibold",children:formatMoney(Ze.Price??0)}),Ze.Rebate&&Ze.Rebate>0&&jsxRuntime.jsxs("span",{className:"text-xs text-green-600",children:["Rebate: ",formatMoney(Ze.Rebate)]}),Ze.EndDate&&jsxRuntime.jsxs("span",{className:"text-xs text-neutral-600",children:["Ends: ",ot(Ze.EndDate)]})]})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"View Opportunity"})})]},ct))})})]})})]}),jsxRuntime.jsxs("div",{className:"flex flex-row flex-wrap justify-between items-end mt-4 gap-4",children:[jsxRuntime.jsxs("div",{className:"flex-shrink-1 flex flex-col gap-3",children:[t.Distribution&&jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:oe>0?jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("span",{className:"text-2xl font-bold whitespace-nowrap",children:["Cost: ",formatMoney(oe)]})}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap",children:[$e>0&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("span",{className:"text-2xl font-bold whitespace-nowrap",children:formatMoney((C?(Ke=(Ct=t.Opportunities)==null?void 0:Ct.find(Ze=>Ze.BidNumber==C.BidNumber))==null?void 0:Ke.Price:Ae)??0)})}),A>0&&jsxRuntime.jsx("span",{className:"text-muted-foreground line-through ml-2 whitespace-nowrap",children:formatMoney($e)})]}),A>0&&jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(Badge,{variant:"outline",className:"bg-red-50 text-red-700 rounded-full px-3 whitespace-nowrap",children:[jsxRuntime.jsxs("span",{children:[A,"% OFF"]}),((Ye=t.InstantRebate)==null?void 0:Ye.EndDate)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",t.InstantRebate.EndDate.split("T")[0]]}),(C==null?void 0:C.EndDate)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",C.EndDate.split("T")[0]]})]})})]})}),jsxRuntime.jsxs(Button$1,{variant:"outline",type:"button",className:"h-11 px-4 text-sm font-medium justify-start w-fit",onClick:()=>te(!0),disabled:!je,children:[jsxRuntime.jsx(ChartLine,{className:"mr-2"}),"View statistics"]})]}),jsxRuntime.jsxs("div",{className:"flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full",children:[f&&jsxRuntime.jsx(Button$1,{className:"gap-2 whitespace-nowrap bg-green-600 hover:bg-green-700",onClick:Ge,disabled:I,children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2"}),"Sync to Shopify"]})}),g,typeof l<"u"&&jsxRuntime.jsxs("div",{className:"flex gap-2 whitespace-nowrap",children:[jsxRuntime.jsxs("div",{className:"flex items-center border rounded-md",children:[jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"rounded-r-none",onClick:st,disabled:typeof S<"u"&&(S<=1||!t.AvailableToBuy||d),children:"-"}),jsxRuntime.jsx("input",{value:S,onChange:at,onBlur:tt,onClick:Ze=>Ze.currentTarget.select(),className:`w-6 @[36rem]:w-12 text-center border-0 focus:ring-0 focus:outline-none ${!t.AvailableToBuy||d?"text-gray-400":""}`,disabled:!t.AvailableToBuy||d}),jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"rounded-l-none",onClick:et,disabled:!t.AvailableToBuy||d,children:"+"})]}),jsxRuntime.jsx(Button$1,{className:"gap-2 whitespace-nowrap",onClick:lt,disabled:!t.AvailableToBuy||d,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Adding..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2"}),"Add to Cart"]})})]})]})]})]})}),jsxRuntime.jsx(Dialog,{open:Q,onOpenChange:te,children:jsxRuntime.jsxs(DialogContent,{className:"w-[min(95vw,1100px)] max-w-5xl space-y-6",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Monthly Sales Performance"}),jsxRuntime.jsxs(DialogDescription,{children:["Expanded product insights for ",ze,Xe?` (SKU ${Xe})`:""]})]}),jsxRuntime.jsx("div",{className:"space-y-6",children:se?jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(AlertTitle,{children:"Unable to load details"}),jsxRuntime.jsx(AlertDescription,{children:se})]}):jsxRuntime.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[jsxRuntime.jsxs("div",{className:"mb-4 space-y-2",children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Rolling 12-month sales dollars and units sold pulled from the detailed endpoint."}),Ve&&jsxRuntime.jsx("div",{"aria-live":"polite","aria-busy":"true",children:jsxRuntime.jsx(Progress,{value:Le,className:"h-2 w-full animate-pulse","aria-label":"Loading performance data"})})]}),jsxRuntime.jsx(SalesChart,{statistics:We,mode:"month",chartHeight:320}),Ve&&jsxRuntime.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Gathering product summary and sales statistics..."})]})})]})})]})}const complexComponents=[`----
1240
+ `;case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return codePointToString(this.readCodePoint());case 116:return" ";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),e){var n=this.pos-1;this.invalidStringToken(n,"Invalid escape sequence in template string")}default:if(t>=48&&t<=55){var o=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],l=parseInt(o,8);return l>255&&(o=o.slice(0,-1),l=parseInt(o,8)),this.pos+=o.length-1,t=this.input.charCodeAt(this.pos),(o!=="0"||t===56||t===57)&&(this.strict||e)&&this.invalidStringToken(this.pos-1-o.length,e?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(l)}return isNewLine(t)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(t)}},pp.readHexChar=function(e){var t=this.pos,n=this.readInt(16,e);return n===null&&this.invalidStringToken(t,"Bad character escape sequence"),n},pp.readWord1=function(){this.containsEsc=!1;for(var e="",t=!0,n=this.pos,o=this.options.ecmaVersion>=6;this.pos<this.input.length;){var l=this.fullCharCodeAtPos();if(isIdentifierChar(l,o))this.pos+=l<=65535?1:2;else if(l===92){this.containsEsc=!0,e+=this.input.slice(n,this.pos);var d=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos;var f=this.readCodePoint();(t?isIdentifierStart:isIdentifierChar)(f,o)||this.invalidStringToken(d,"Invalid Unicode escape"),e+=codePointToString(f),n=this.pos}else break;t=!1}return e+this.input.slice(n,this.pos)},pp.readWord=function(){var e=this.readWord1(),t=types$1.name;return this.keywords.test(e)&&(t=keywords[e]),this.finishToken(t,e)};var version="8.12.1";Parser.acorn={Parser,version,defaultOptions,Position,SourceLocation,getLineInfo,Node:Node$3,TokenType,tokTypes:types$1,keywordTypes:keywords,TokContext,tokContexts:types,isIdentifierChar,isIdentifierStart,Token,isNewLine,lineBreak,lineBreakG,nonASCIIwhitespace};var AcornJSX=__toESM(require_acorn_jsx()),attributeNames_default={acceptcharset:"acceptCharset",accesskey:"accessKey",allowfullscreen:"allowFullScreen",autocapitalize:"autoCapitalize",autocomplete:"autoComplete",autofocus:"autoFocus",autoplay:"autoPlay",cellpadding:"cellPadding",cellspacing:"cellSpacing",charset:"charSet",class:"className",colspan:"colSpan",contenteditable:"contentEditable",crossorigin:"crossOrigin",datetime:"dateTime",enctype:"encType",for:"htmlFor",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",frameborder:"frameBorder",hreflang:"hrefLang",httpequiv:"httpEquiv",inputmode:"inputMode",keyparams:"keyParams",keytype:"keyType",marginheight:"marginHeight",marginwidth:"marginWidth",maxlength:"maxLength",mediagroup:"mediaGroup",minlength:"minLength",novalidate:"noValidate",radiogroup:"radioGroup",readonly:"readOnly",referrerpolicy:"referrerPolicy",rowspan:"rowSpan",spellcheck:"spellCheck",srcdoc:"srcDoc",srclang:"srcLang",srcset:"srcSet",tabindex:"tabIndex",usemap:"useMap"},VOID_ELEMENTS=["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],NO_WHITESPACE=["table","tbody","tfoot","thead","tr"];function canHaveChildren(e){return VOID_ELEMENTS.indexOf(e.toLowerCase())===-1}function canHaveWhitespace(e){return NO_WHITESPACE.indexOf(e.toLowerCase())!==-1}class NullishShortCircuit extends Error{constructor(t="Nullish value encountered"){super(t),this.name="NullishShortCircuit"}}var hash=(e="",t=16)=>{const n=String(e);let o=0;return n.split("").forEach(l=>{o=(o<<5)-o+l.charCodeAt(0),o&=o}),Math.abs(o).toString(t)},randomHash=()=>hash(Math.random().toString()),camelCase=e=>e.replace(/([A-Z])([A-Z])/g,"$1 $2").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[^a-zA-Z\u00C0-\u00ff]/g," ").toLowerCase().split(" ").filter(t=>t).map((t,n)=>n>0?t[0].toUpperCase()+t.slice(1):t).join(""),parseStyle=e=>{switch(typeof e){case"string":return e.split(";").filter(t=>t).reduce((t,n)=>{const o=n.slice(0,n.indexOf(":")).trim(),l=n.slice(n.indexOf(":")+1).trim();return{...t,[camelCase(o)]:l}},{});case"object":return e;default:return}},pathToArrayPath=e=>e==null||e===""?[]:e.split("."),resolveArrayPath=(e,t)=>{const[n,...o]=t;if(!(e==null||n==null))return o.length===0?e[n]:resolveArrayPath(e[n],o)},resolvePath=(e,t)=>resolveArrayPath(e,pathToArrayPath(t));function handleNaN(e){return Number.isNaN(e)?"NaN":e}class JsxParser extends React.Component{constructor(){super(...arguments);en(this,"ParsedChildren",null);zn(this,fn,n=>{const o=Parser.extend(AcornJSX.default({autoCloseVoidElements:this.props.autoCloseVoidElements})),l=`<root>${n}</root>`;let d=[];try{return d=o.parse(l,{ecmaVersion:"latest"}),d=d.body[0].expression.children||[],d.map(f=>on(this,rn).call(this,f)).filter(Boolean)}catch(f){return this.props.showWarnings&&console.warn(f),this.props.onError&&this.props.onError(f),this.props.renderError?this.props.renderError({error:String(f)}):null}});zn(this,rn,(n,o)=>{var l,d;switch(n.type){case"JSXAttribute":return n.value===null?!0:on(this,rn).call(this,n.value,o);case"JSXElement":case"JSXFragment":return on(this,Qn).call(this,n,o);case"JSXExpressionContainer":return on(this,rn).call(this,n.expression,o);case"JSXText":const f=this.props.disableKeyGeneration?void 0:randomHash();return this.props.disableFragments?n.value:React.createElement(React.Fragment,{key:f},n.value);case"ArrayExpression":return n.elements.map(A=>on(this,rn).call(this,A,o));case"BinaryExpression":const g=on(this,rn).call(this,n.left,o),b=on(this,rn).call(this,n.right,o);let _;switch(n.operator){case"-":_=g-b;break;case"!=":_=g!=b;break;case"!==":_=g!==b;break;case"*":_=g*b;break;case"**":_=g**b;break;case"/":_=g/b;break;case"%":_=g%b;break;case"+":_=g+b;break;case"<":_=g<b;break;case"<=":_=g<=b;break;case"==":_=g==b;break;case"===":_=g===b;break;case">":_=g>b;break;case">=":_=g>=b;break;default:this.props.onError(new Error(`Unsupported binary operator: ${n.operator}`));return}return handleNaN(_);case"CallExpression":const S=on(this,rn).call(this,n.callee,o);if(S===void 0){if(n.optional)throw new NullishShortCircuit;this.props.onError(new Error(`The expression '${n.callee}' could not be resolved, resulting in an undefined return value.`));return}return S(...n.arguments.map(A=>on(this,rn).call(this,A,o)));case"ConditionalExpression":return on(this,rn).call(this,n.test,o)?on(this,rn).call(this,n.consequent,o):on(this,rn).call(this,n.alternate,o);case"ExpressionStatement":return on(this,rn).call(this,n.expression,o);case"Identifier":return n.name==="Infinity"?1/0:n.name==="-Infinity"?-1/0:n.name==="NaN"?NaN:o&&n.name in o?handleNaN(o[n.name]):handleNaN((this.props.bindings||{})[n.name]);case"Literal":return n.value;case"LogicalExpression":const R=on(this,rn).call(this,n.left,o);return n.operator==="||"&&R?R:n.operator==="&&"&&R||n.operator==="||"&&!R?on(this,rn).call(this,n.right,o):!1;case"MemberExpression":return on(this,ar).call(this,n,o);case"ChainExpression":return on(this,ir).call(this,n,o);case"ObjectExpression":const C={};return n.properties.forEach(A=>{C[A.key.name||A.key.value]=on(this,rn).call(this,A.value,o)}),C;case"TemplateElement":return n.value.cooked;case"TemplateLiteral":return[...n.expressions,...n.quasis].sort((A,M)=>A.start<M.start?-1:1).map(A=>on(this,rn).call(this,A,o)).join("");case"UnaryExpression":const E=on(this,rn).call(this,n.argument,o);switch(n.operator){case"+":return+E;case"-":return-E;case"!":return!E;case"~":return~E;case"typeof":return typeof E}return;case"ArrowFunctionExpression":return(n.async||n.generator)&&((d=(l=this.props).onError)==null||d.call(l,new Error("Async and generator arrow functions are not supported."))),(...A)=>{const M={...o};return n.params.forEach((I,j)=>{M[I.name]=A[j]}),on(this,rn).call(this,n.body,M)};default:this.props.onError(new Error(`The expression type '${n.type}' is not supported.`));return}});zn(this,ir,(n,o)=>{try{return on(this,rn).call(this,n.expression,o)}catch(l){if(l instanceof NullishShortCircuit)return;throw l}});zn(this,ar,(n,o)=>{const l=on(this,rn).call(this,n.object,o);let d;if(n.computed)d=on(this,rn).call(this,n.property,o);else if(n.property.type==="Identifier")d=n.property.name;else{this.props.onError(new Error("Only simple MemberExpressions are supported."));return}if(l==null&&n.optional)throw new NullishShortCircuit;let f;try{f=l[d]}catch{this.props.onError(new Error(`The property '${d}' could not be resolved on the object '${l}'.`));return}return typeof f=="function"?f.bind(l):f});zn(this,Wn,n=>n.type==="JSXIdentifier"?n.name:`${on(this,Wn).call(this,n.object)}.${on(this,Wn).call(this,n.property)}`);zn(this,Qn,(n,o)=>{const{allowUnknownElements:l,components:d,componentsOnly:f,onError:g}=this.props,{children:b=[]}=n,_=n.type==="JSXElement"?n.openingElement:n.openingFragment,{attributes:S=[]}=_,R=n.type==="JSXElement"?on(this,Wn).call(this,_.name):"",C=(this.props.blacklistedAttrs||[]).map(Q=>Q instanceof RegExp?Q:new RegExp(Q,"i")),E=(this.props.blacklistedTags||[]).map(Q=>Q.trim().toLowerCase()).filter(Boolean);if(/^(html|head|body)$/i.test(R))return b.map(Q=>on(this,Qn).call(this,Q,o));const A=R.trim().toLowerCase();if(E.indexOf(A)!==-1)return g(new Error(`The tag <${R}> is blacklisted, and will not be rendered.`)),null;if(R!==""&&!resolvePath(d,R)){if(f)return g(new Error(`The component <${R}> is unrecognized, and will not be rendered.`)),this.props.renderUnrecognized(R);if(!l&&document.createElement(R)instanceof HTMLUnknownElement)return g(new Error(`The tag <${R}> is unrecognized in this browser, and will not be rendered.`)),this.props.renderUnrecognized(R)}let M,I=n.type==="JSXElement"?resolvePath(d,R):React.Fragment;if(I||canHaveChildren(R)){if(M=b.map(te=>on(this,rn).call(this,te,o)),R.includes(".")){const F=R.split(".").reduce((V,ne)=>V?V[ne]:d==null?void 0:d[ne],null);F&&(I=F)}!I&&!canHaveWhitespace(R)&&(M=M.filter(te=>typeof te!="string"||!/^\s*$/.test(te)));const Q=M.find(te=>typeof te=="function");M.length===0?M=void 0:Q?M=Q:M.length===1?[M]=M:M.length>1&&!this.props.disableKeyGeneration&&(M=M.map((te,F)=>te!=null&&te.type&&!(te!=null&&te.key)?{...te,key:te.key||F}:te))}const j={key:this.props.disableKeyGeneration?void 0:randomHash()};S.forEach(Q=>{if(Q.type==="JSXAttribute"){const te=Q.name.name,F=attributeNames_default[te]||te,V=on(this,rn).call(this,Q,o);C.filter(ae=>ae.test(F)).length===0&&(j[F]=V)}else if(Q.type==="JSXSpreadAttribute"&&Q.argument.type==="Identifier"||Q.argument.type==="MemberExpression"){const te=on(this,rn).call(this,Q.argument,o);typeof te=="object"&&Object.keys(te).forEach(F=>{const V=attributeNames_default[F]||F;C.filter(ae=>ae.test(V)).length===0&&(j[V]=te[F])})}}),typeof j.style=="string"&&(j.style=parseStyle(j.style));const q=R.toLowerCase();return q==="option"&&(M=M.props.children),React.createElement(I||q,j,M)})}render(){const n=(this.props.jsx||"").trim().replace(/<!DOCTYPE([^>]*)>/g,"");this.ParsedChildren=on(this,fn).call(this,n);const o=[...new Set(["jsx-parser",...String(this.props.className).split(" ")])].filter(Boolean).join(" ");return this.props.renderInWrapper?React.createElement("div",{className:o},this.ParsedChildren):this.ParsedChildren}}fn=new WeakMap,rn=new WeakMap,ir=new WeakMap,ar=new WeakMap,Wn=new WeakMap,Qn=new WeakMap,en(JsxParser,"displayName","JsxParser"),en(JsxParser,"defaultProps",{allowUnknownElements:!0,autoCloseVoidElements:!1,bindings:{},blacklistedAttrs:[/^on.+/i],blacklistedTags:["script"],className:"",components:{},componentsOnly:!1,disableFragments:!1,disableKeyGeneration:!1,jsx:"",onError:()=>{},showWarnings:!1,renderError:void 0,renderInWrapper:!0,renderUnrecognized:()=>null});var source_default=JsxParser;const CountryFlag=({countryCode:e,className:t=""})=>{const[n,o]=React.useState(null),[l,d]=React.useState(!1);return React.useEffect(()=>{if(!e)return;const g=`https://purecatamphetamine.github.io/country-flag-icons/3x2/${e.toUpperCase()}.svg`;fetch(g,{method:"HEAD"}).then(b=>{b.ok?(o(g),d(!1)):d(!0)}).catch(()=>{d(!0)})},[e]),l||!n?jsxRuntime.jsx("span",{className:t,children:e}):jsxRuntime.jsx("img",{src:n,alt:`${e} flag`,className:`inline-block ${t}`,style:{width:"24px",height:"auto"}})};function ProductCard({applicationId:e,product:t,viewProductLink:n,defaultOpportunityNumber:o="",onAddToCart:l,addingToCart:d=!1,shopifyHostname:f,customAction:g=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var $t,rt,Rt,dt,It,Mt,Ct,Ke,Ye;const b=reactRouterDom.useNavigate(),{toast:_}=useToast(),[S,R]=React.useState(1),[C,E]=React.useState(null),[A,M]=React.useState(0),[I,j]=React.useState(!1),[q]=usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[Q,te]=React.useState(!1),[F,V]=React.useState(null),[ne,ae]=React.useState("idle"),[se,Oe]=React.useState(null),[Ne]=useLazyGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery(),oe=(($t=t==null?void 0:t.Distribution)==null?void 0:$t.Cost)||0,$e=((rt=t==null?void 0:t.Distribution)==null?void 0:rt.RegularPrice)||0,Ae=((Rt=t==null?void 0:t.Distribution)==null?void 0:Rt.Price)||0,je=!!(e&&(t!=null&&t.RandmarSKU));React.useEffect(()=>{R(1),E(null),M(0)},[t==null?void 0:t.RandmarSKU]),React.useEffect(()=>{var Ze;if(t&&o){const ct=(Ze=t.Opportunities)==null?void 0:Ze.find(mt=>mt.BidNumber==o);ct&&Be(ct)&&E(ct)}},[t,o]),React.useEffect(()=>{if(!t)return;const Ze=C!=null&&C.Price?C.Price:Ae;M($e>0?Math.round(($e-Ze)/$e*100):0)},[t,C,Ae,$e]),React.useEffect(()=>{d||R(1)},[d]),React.useEffect(()=>{if(!Q){V(null),ae("idle"),Oe(null);return}if(!e||!(t!=null&&t.RandmarSKU)){ae("error"),Oe("Missing identifiers to load performance data.");return}let Ze=!1;const ct=t.RandmarSKU;return(async()=>{ae("summary"),Oe(null);try{const ft=await Ne({routeApplicationId:e,randmarSku:ct,withSpecification:!1});if(Ze)return;if("error"in ft&&ft.error)throw ft.error;V(ft.data??null),ae("detailed");const yt=await Ne({routeApplicationId:e,randmarSku:ct,withSpecification:!0});if(Ze)return;if("error"in yt&&yt.error)throw yt.error;V(yt.data??ft.data??null),ae("complete")}catch(ft){if(Ze)return;console.error("Failed to load performance data for product modal",ft),ae("error"),Oe("We couldn't load the performance details. Please try again.")}})(),()=>{Ze=!0}},[e,Ne,Q,t==null?void 0:t.RandmarSKU]);const Be=Ze=>{if(Ze.Active!==!0)return!1;const ct=new Date().toISOString().split("T")[0];return!(Ze.EndDate&&Ze.EndDate.split("T")[0]<ct||Ze.StartDate&&Ze.StartDate.split("T")[0]>ct)},qe=Ze=>Ze>=90?{label:"Top 10% Bestseller",color:"text-purple-950",bgColor:"bg-purple-200"}:Ze>=75?{label:"Bestseller",color:"text-blue-700",bgColor:"bg-blue-50"}:Ze>=33?{label:"Popular",color:"text-green-700",bgColor:"bg-green-50"}:{label:"Rising",color:"text-gray-700",bgColor:"bg-white"},Ve=ne!=="complete"&&ne!=="error",Le=ne==="summary"?40:ne==="detailed"?80:10,He=(F==null?void 0:F.SalesStatistics)??[],We=Ve?[]:He,ze=(F==null?void 0:F.RandmarTitle)??(t==null?void 0:t.RandmarTitle)??(t==null?void 0:t.RandmarSKU)??"this product",Xe=(F==null?void 0:F.RandmarSKU)??(t==null?void 0:t.RandmarSKU);if(!t)return jsxRuntime.jsx(Card,{children:jsxRuntime.jsxs(CardContent,{className:"p-6",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx("div",{className:"h-10 w-24 flex items-center justify-end ml-4",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded-md"})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-20 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-24 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-28 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"flex gap-6",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-6 flex-1",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-12 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:jsxRuntime.jsx("div",{className:"w-60 h-40",children:jsxRuntime.jsx(Skeleton,{className:"w-full h-full rounded-lg"})})})]}),jsxRuntime.jsxs("div",{className:"flex gap-6 mt-4",children:[jsxRuntime.jsx("div",{className:"flex flex-1",children:jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-24 mb-3"}),jsxRuntime.jsx(Skeleton,{className:"h-16 w-full rounded-md"})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-32 rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24 mt-4"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-6 mt-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-start gap-1 mb-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 flex-1 rounded-md"})]})]})]})});const nt=(t==null?void 0:t.Opportunities)||[],Je=nt.length>0,st=()=>{if(S==null){R(1);return}S>1&&R(S-1)},et=()=>{if(S==null){R(1);return}R(S+1)},at=Ze=>{const ct=Number.parseInt(Ze.target.value,10);if(!isNaN(ct)&&ct>0){R(ct);return}R(void 0)},tt=()=>{(S==null||S<1)&&R(1)},ot=Ze=>{try{return new Date(Ze).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(ct){return console.error(ct),Ze.split("T")[0]||"N/A"}},lt=()=>{typeof l<"u"&&l({quantity:S??1,bidNumber:(C==null?void 0:C.BidNumber)??null})},Ge=()=>{I||!f||(j(!0),q({routeResellerId:e??"",randmarSku:t.RandmarSKU??"",shopifyHostName:f}).then(Ze=>{if(Ze.error){console.error("Error syncing to Shopify:",Ze.error),_({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"});return}_({title:"Product synced",description:"Product synced to Shopify successfully",variant:"success"})}).catch(Ze=>{console.error("Error syncing to Shopify:",Ze),_({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"})}).finally(()=>{j(!1)}))};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Card,{className:"w-full hover:shadow-lg transition-shadow @container",children:jsxRuntime.jsxs(CardContent,{className:"p-6",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-3",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-xl",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex items-center justify-end ml-4 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40},`partner_logo_${t.ManufacturerId}`)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col @[36rem]:flex-row gap-6",children:[jsxRuntime.jsxs("div",{className:"flex-1 @[36rem]:order-1 order-2 flex flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center justify-center @[36rem]:items-start @[36rem]:justify-start",children:[t.State&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.State==="Active"?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(Check,{size:"12",className:"mr-1.5"})," ",t.State]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.SerialNumber?"bg-green-50 text-green-700 hover:bg-green-50":"bg-yellow-50 text-yellow-700 hover:bg-yellow-50"}`,children:[jsxRuntime.jsx(QrCode,{size:"12",className:"mr-1.5"})," ",t.SerialNumber?"Serialized":"Unserialized"]}),t.TransparencyCode&&jsxRuntime.jsxs(Badge,{variant:"outline",className:"rounded-full px-3 bg-green-50 text-green-700 hover:bg-green-50",children:[jsxRuntime.jsx(CircleDashed,{size:"12",className:"mr-1.5"})," Transparency Code"]}),t.AvailableToBuy!==void 0&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.AvailableToBuy?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(ShoppingCart,{size:"12",className:"mr-1.5"})," ",t.AvailableToBuy?"Available":"Unavailable"]}),t.ManufacturerCategory!==void 0&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${(dt=t.ManufacturerCategory)!=null&&dt.QualificationRequired?"bg-blue-50 text-blue-700 hover:bg-blue-50":"bg-neutral-50 text-neutral-700 hover:bg-neutral-50"}`,children:[jsxRuntime.jsx(ShieldCheck,{size:"12",className:"mr-1.5"})," ",(It=t.ManufacturerCategory)!=null&&It.QualificationRequired?"Qualified Only":"Available to all"]}),t.ManufacturerId&&jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.AutoUpdate?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(RefreshCw,{size:"12",className:"mr-1.5"})," ",t.AutoUpdate?`Automatic Reorder (${t.MasterCarton})`:"Manually Reorders"]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:`rounded-full px-3 ${t.BodyHTML&&t.Title&&t.MAP?"bg-green-50 text-green-700 hover:bg-green-50":"bg-red-50 text-red-700 hover:bg-red-50"}`,children:[jsxRuntime.jsx(Store,{size:"12",className:"mr-1.5"})," ",t.BodyHTML&&t.Title&&t.MAP?"Shopify Ready":"Not Shopify Ready"]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-4 flex-1",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"MPN"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.MPN||"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"UPC"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.UPC||"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"Unit Weight"}),jsxRuntime.jsx("div",{className:"font-medium",children:t.UnitWeight?`${formatNumber(t.UnitWeight)} lbs`:"N/A"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"text-sm text-muted-foreground",children:["MAP",jsxRuntime.jsx("span",{className:"text-primary",children:" / "}),"MSRP"]}),jsxRuntime.jsxs("div",{className:"font-medium",children:[t.MAP?formatMoney(t.MAP):"N/A",jsxRuntime.jsx("span",{className:"text-primary",children:" / "}),t.MSRP?formatMoney(t.MSRP):"N/A"]})]}),!!t.OverallPercentileRank&&!!t.ManufacturerPercentileRank&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"Bestseller Status"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{children:"Global: "}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Badge,{variant:"outline",className:`rounded-full px-3 w-fit ${qe(t.OverallPercentileRank).bgColor} ${qe(t.OverallPercentileRank).color} hover:${qe(t.OverallPercentileRank).bgColor}`,children:qe(t.OverallPercentileRank).label})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["Percentile Rank: ",t.OverallPercentileRank]})})]})})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{children:[t.ManufacturerName,": "]}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Badge,{variant:"outline",className:`rounded-full px-3 w-fit ${qe(t.ManufacturerPercentileRank).bgColor} ${qe(t.ManufacturerPercentileRank).color} hover:${qe(t.ManufacturerPercentileRank).bgColor}`,children:qe(t.ManufacturerPercentileRank).label})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["Percentile Rank: ",t.ManufacturerPercentileRank]})})]})})]})]})]}),t.CountryCodeOfOrigin&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-sm text-muted-foreground",children:"Origin"}),jsxRuntime.jsxs("div",{className:"font-medium flex items-center",children:[jsxRuntime.jsx(CountryFlag,{countryCode:t.CountryCodeOfOrigin,className:"mr-2"}),t.CountryCodeOfOrigin]})]})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col @[36rem]:order-2 order-1 items-center",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""},`product_image_${t.RandmarSKU}`)})]}),jsxRuntime.jsx("div",{className:"flex flex-col @[36rem]:flex-row gap-6 mt-4",children:jsxRuntime.jsx("div",{className:"flex flex-1 @[36rem]:order-1 order-2",children:Je&&t.Distribution&&jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:"You have "+nt.length+(nt.length>1?" opportunities":" opportunity")+" for this product:"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1",children:nt.map((Ze,ct)=>Be(Ze)?jsxRuntime.jsxs("div",{className:`flex justify-between items-center rounded-lg transition-colors py-2 px-4 border border-muted cursor-pointer ${Ze.BidNumber==(C==null?void 0:C.BidNumber)?"bg-purple-100 border-2 border-purple-900":"bg-white border-1 border-purple-600 hover:bg-purple-200"}`,onClick:()=>{E(Ze.BidNumber!==(C==null?void 0:C.BidNumber)?Ze:null)},children:[jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium text-sm",children:Ze.Opportunity}),jsxRuntime.jsx("span",{className:"text-xs text-neutral-900",children:Ze.BidNumber})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{className:"font-semibold",children:formatMoney(Ze.Price??0)}),Ze.Rebate&&Ze.Rebate>0&&jsxRuntime.jsxs("span",{className:"text-xs text-green-600",children:["Rebate: ",formatMoney(Ze.Rebate)]}),Ze.EndDate&&jsxRuntime.jsxs("span",{className:"text-xs text-neutral-600",children:["Ends: ",ot(Ze.EndDate)]})]})]},ct):jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-purple-100 border border-muted cursor-pointer !bg-neutral-50 hover:bg-neutral-100",onClick:()=>{Ze.BidNumber&&b(`/${e}/Opportunity/${Ze.ManufacturerId}/${Ze.BidNumber}`)},children:[jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium text-sm",children:Ze.Opportunity}),jsxRuntime.jsxs("span",{className:"text-xs text-neutral-900",children:[Ze.BidNumber," ",jsxRuntime.jsx(Badge,{variant:"outline",className:"text-xs mx-1 h-5 bg-gray-100",children:"Currently unavailable"})]})]})}),jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{className:"font-semibold",children:formatMoney(Ze.Price??0)}),Ze.Rebate&&Ze.Rebate>0&&jsxRuntime.jsxs("span",{className:"text-xs text-green-600",children:["Rebate: ",formatMoney(Ze.Rebate)]}),Ze.EndDate&&jsxRuntime.jsxs("span",{className:"text-xs text-neutral-600",children:["Ends: ",ot(Ze.EndDate)]})]})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"View Opportunity"})})]},ct))})})]})})}),jsxRuntime.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-row flex-wrap justify-between items-end gap-4",children:[jsxRuntime.jsx("div",{className:"flex flex-col gap-3 flex-1",children:t.Distribution&&jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:oe>0?jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs("span",{className:"text-2xl font-bold whitespace-nowrap",children:["Cost: ",formatMoney(oe)]})}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap",children:[$e>0&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("span",{className:"text-2xl font-bold whitespace-nowrap",children:formatMoney((C?(Ct=(Mt=t.Opportunities)==null?void 0:Mt.find(Ze=>Ze.BidNumber==C.BidNumber))==null?void 0:Ct.Price:Ae)??0)})}),A>0&&jsxRuntime.jsx("span",{className:"text-muted-foreground line-through ml-2 whitespace-nowrap",children:formatMoney($e)})]}),A>0&&jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(Badge,{variant:"outline",className:"bg-red-50 text-red-700 rounded-full px-3 whitespace-nowrap",children:[jsxRuntime.jsxs("span",{children:[A,"% OFF"]}),((Ke=t.InstantRebate)==null?void 0:Ke.EndDate)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",t.InstantRebate.EndDate.split("T")[0]]}),(C==null?void 0:C.EndDate)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",C.EndDate.split("T")[0]]})]})})]})})}),jsxRuntime.jsxs("div",{className:"flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full @[36rem]:w-auto",children:[f&&jsxRuntime.jsx(Button$1,{className:"gap-2 whitespace-nowrap bg-green-600 hover:bg-green-700",onClick:Ge,disabled:I,children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2"}),"Sync to Shopify"]})}),g,typeof l<"u"&&jsxRuntime.jsxs("div",{className:"flex gap-2 whitespace-nowrap",children:[jsxRuntime.jsxs("div",{className:"flex items-center border rounded-md",children:[jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"rounded-r-none",onClick:st,disabled:typeof S<"u"&&(S<=1||!t.AvailableToBuy||d),children:"-"}),jsxRuntime.jsx("input",{value:S,onChange:at,onBlur:tt,onClick:Ze=>Ze.currentTarget.select(),className:`w-6 @[36rem]:w-12 text-center border-0 focus:ring-0 focus:outline-none ${!t.AvailableToBuy||d?"text-gray-400":""}`,disabled:!t.AvailableToBuy||d}),jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"rounded-l-none",onClick:et,disabled:!t.AvailableToBuy||d,children:"+"})]}),jsxRuntime.jsx(Button$1,{className:"gap-2 whitespace-nowrap",onClick:lt,disabled:!t.AvailableToBuy||d,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Adding..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2"}),"Add to Cart"]})})]})]})]}),jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-2 @[36rem]:flex-row",children:[jsxRuntime.jsx("div",{className:"flex-1 min-w-[10rem]",children:jsxRuntime.jsxs(Button$1,{variant:"outline",type:"button",className:"h-11 px-4 text-sm font-medium justify-start w-full",onClick:()=>te(!0),disabled:!je,children:[jsxRuntime.jsx(ChartLine,{className:"mr-2"}),"View statistics"]})}),jsxRuntime.jsx("div",{className:"flex-1 min-w-[10rem]",children:jsxRuntime.jsx(ProductInventoryButton,{applicationId:e??"",randmarSku:t.RandmarSKU??"",inventory:(Ye=t.Distribution)==null?void 0:Ye.Inventory,buttonSize:"lg",buttonClassName:"w-full h-11 justify-start"})}),n&&jsxRuntime.jsx(reactRouterDom.Link,{to:n,className:"flex-1 min-w-[10rem]",children:jsxRuntime.jsxs(Button$1,{variant:"outline",className:"h-11 px-4 text-sm font-medium justify-start w-full",children:[jsxRuntime.jsx(Eye,{className:"mr-2"}),"View Product"]})})]})]})]})}),jsxRuntime.jsx(Dialog,{open:Q,onOpenChange:te,children:jsxRuntime.jsxs(DialogContent,{className:"w-[min(95vw,1100px)] max-w-5xl space-y-6",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Monthly Sales Performance"}),jsxRuntime.jsxs(DialogDescription,{children:["Expanded product insights for ",ze,Xe?` (SKU ${Xe})`:""]})]}),jsxRuntime.jsx("div",{className:"space-y-6",children:se?jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(AlertTitle,{children:"Unable to load details"}),jsxRuntime.jsx(AlertDescription,{children:se})]}):jsxRuntime.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[jsxRuntime.jsxs("div",{className:"mb-4 space-y-2",children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Rolling 12-month sales dollars and units sold pulled from the detailed endpoint."}),Ve&&jsxRuntime.jsx("div",{"aria-live":"polite","aria-busy":"true",children:jsxRuntime.jsx(Progress,{value:Le,className:"h-2 w-full animate-pulse","aria-label":"Loading performance data"})})]}),jsxRuntime.jsx(SalesChart,{statistics:We,mode:"month",chartHeight:320}),Ve&&jsxRuntime.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Gathering product summary and sales statistics..."})]})})]})})]})}const complexComponents=[`----
1241
1241
  PartnerCard: For data that fits this shape:
1242
1242
  { "ApplicationId": "19022", "PublicName": "BiOSS", "VoiceName": null, "VoiceStyle": null, "About": "example", "SceneName": "Kitchen Counter", "IsReseller": true, "IsManufacturer": true, "IsSalesAgency": false, "Socials": [ { "ApplicationId": "19022", "SocialNetwork": "Facebook", "Tag": "@bioss.ca" }, { "ApplicationId": "19022", "SocialNetwork": "Instagram", "Tag": "@bioss.ca" }, { "ApplicationId": "19022", "SocialNetwork": "LinkedIn", "Tag": "@biossinc" }, { "ApplicationId": "19022", "SocialNetwork": "Youtube", "Tag": "@biosssolutionssanitairessa4095" } ], "Manufacturer": null, "Reseller": null }
1243
1243
  Use <PartnerCard account={data} action={<></>}>`,`----
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "randmarcomps",
3
3
  "private": false,
4
- "version": "1.482.0",
4
+ "version": "1.484.0",
5
5
  "description": "The UI library enabling speed and consistency in Randmar frontends.",
6
6
  "type": "module",
7
7
  "files": [