randmarcomps 1.232.0 → 1.233.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/randmarcomps.js +27 -38
- package/dist/randmarcomps.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/randmarcomps.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var Bn = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var hn = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
5
|
var jn = (e, t, n) => t in e ? Bn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
6
|
-
var Yt = (e, t, n) => jn(e, typeof t != "symbol" ? t + "" : t, n), Ln = (e, t, n) => t.has(e) ||
|
|
7
|
-
var Xt = (e, t, n) => (Ln(e, t, "read from private field"), n ? n.call(e) : t.get(e)), dr = (e, t, n) => t.has(e) ?
|
|
6
|
+
var Yt = (e, t, n) => jn(e, typeof t != "symbol" ? t + "" : t, n), Ln = (e, t, n) => t.has(e) || hn("Cannot " + n);
|
|
7
|
+
var Xt = (e, t, n) => (Ln(e, t, "read from private field"), n ? n.call(e) : t.get(e)), dr = (e, t, n) => t.has(e) ? hn("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
8
8
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
9
9
|
import * as React from "react";
|
|
10
10
|
import React__default, { forwardRef, createElement, useState, useLayoutEffect, useEffect, createContext, useRef, useContext, useCallback, useDebugValue, useMemo, isValidElement, Children, PureComponent, useImperativeHandle, cloneElement, Component, Fragment as Fragment$1 } from "react";
|
|
@@ -58059,10 +58059,10 @@ Defaulting to 2020, but this will stop working in the future.`)), ne.ecmaVersion
|
|
|
58059
58059
|
var O = this.readWord1(), ne = j.name;
|
|
58060
58060
|
return this.keywords.test(O) && (ne = Q[O]), this.finishToken(ne, O);
|
|
58061
58061
|
};
|
|
58062
|
-
var
|
|
58062
|
+
var pn = "8.12.1";
|
|
58063
58063
|
rt.acorn = {
|
|
58064
58064
|
Parser: rt,
|
|
58065
|
-
version:
|
|
58065
|
+
version: pn,
|
|
58066
58066
|
defaultOptions: Ke,
|
|
58067
58067
|
Position: He,
|
|
58068
58068
|
SourceLocation: Ye,
|
|
@@ -58090,7 +58090,7 @@ Defaulting to 2020, but this will stop working in the future.`)), ne.ecmaVersion
|
|
|
58090
58090
|
function Dn(O, ne) {
|
|
58091
58091
|
return rt.tokenizer(O, ne);
|
|
58092
58092
|
}
|
|
58093
|
-
n.Node = _r, n.Parser = rt, n.Position = He, n.SourceLocation = Ye, n.TokContext = nr, n.Token = Mr, n.TokenType = A, n.defaultOptions = Ke, n.getLineInfo = Je, n.isIdentifierChar = M, n.isIdentifierStart = I, n.isNewLine = ie, n.keywordTypes = Q, n.lineBreak = te, n.lineBreakG = ae, n.nonASCIIwhitespace = se, n.parse = On, n.parseExpressionAt = Vn, n.tokContexts = Zt, n.tokTypes = j, n.tokenizer = Dn, n.version =
|
|
58093
|
+
n.Node = _r, n.Parser = rt, n.Position = He, n.SourceLocation = Ye, n.TokContext = nr, n.Token = Mr, n.TokenType = A, n.defaultOptions = Ke, n.getLineInfo = Je, n.isIdentifierChar = M, n.isIdentifierStart = I, n.isNewLine = ie, n.keywordTypes = Q, n.lineBreak = te, n.lineBreakG = ae, n.nonASCIIwhitespace = se, n.parse = On, n.parseExpressionAt = Vn, n.tokContexts = Zt, n.tokTypes = j, n.tokenizer = Dn, n.version = pn;
|
|
58094
58094
|
});
|
|
58095
58095
|
}), require_acorn_jsx = __commonJS((e, t) => {
|
|
58096
58096
|
var n = require_xhtml(), o = /^[\da-fA-F]+$/, l = /^\d+$/, d = /* @__PURE__ */ new WeakMap();
|
|
@@ -70532,7 +70532,8 @@ function ManufacturerOverviewPage({
|
|
|
70532
70532
|
isLoading: d,
|
|
70533
70533
|
isError: f
|
|
70534
70534
|
} = useGetV4PartnerByApplicationIdAccountManufacturerQuery({
|
|
70535
|
-
applicationId: e
|
|
70535
|
+
applicationId: e,
|
|
70536
|
+
withSpecification: !0
|
|
70536
70537
|
}), [g, b] = useState({
|
|
70537
70538
|
publicInfo: {
|
|
70538
70539
|
hasUnsavedChanges: !1
|
|
@@ -70544,16 +70545,16 @@ function ManufacturerOverviewPage({
|
|
|
70544
70545
|
hasUnsavedChanges: !1
|
|
70545
70546
|
}
|
|
70546
70547
|
// Add other forms here if needed
|
|
70547
|
-
}), _ = useCallback(() => t ? !1 : g.publicInfo.hasUnsavedChanges || g.qualifications.hasUnsavedChanges || g.billingInfo.hasUnsavedChanges, [t, g]), S = useCallback((
|
|
70548
|
-
b((
|
|
70549
|
-
var
|
|
70550
|
-
return ((
|
|
70551
|
-
...
|
|
70552
|
-
[
|
|
70553
|
-
}) :
|
|
70548
|
+
}), _ = useCallback(() => t ? !1 : g.publicInfo.hasUnsavedChanges || g.qualifications.hasUnsavedChanges || g.billingInfo.hasUnsavedChanges, [t, g]), S = useCallback((I, M) => {
|
|
70549
|
+
b((A) => {
|
|
70550
|
+
var V;
|
|
70551
|
+
return ((V = A[I]) == null ? void 0 : V.hasUnsavedChanges) !== M.hasUnsavedChanges ? (console.log(`Updating form state for ${I}:`, M.hasUnsavedChanges), {
|
|
70552
|
+
...A,
|
|
70553
|
+
[I]: M
|
|
70554
|
+
}) : A;
|
|
70554
70555
|
});
|
|
70555
|
-
}, []), { NavigationGuardDialog: C } = useRouterNavigationGuard(_), [E, R] = useState(!0)
|
|
70556
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
70556
|
+
}, []), { NavigationGuardDialog: C } = useRouterNavigationGuard(_), [E, R] = useState(!0);
|
|
70557
|
+
return !d && (l != null && l.SalesStatistics) && l.SalesStatistics.length > 0, /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
70557
70558
|
f ? /* @__PURE__ */ jsx(Card, { className: "p-6", children: /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
|
|
70558
70559
|
/* @__PURE__ */ jsx(CircleAlert, { className: "h-4 w-4" }),
|
|
70559
70560
|
/* @__PURE__ */ jsx(AlertTitle, { children: "Error" }),
|
|
@@ -70568,25 +70569,13 @@ function ManufacturerOverviewPage({
|
|
|
70568
70569
|
}
|
|
70569
70570
|
),
|
|
70570
70571
|
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-6", children: [
|
|
70571
|
-
/* @__PURE__ */
|
|
70572
|
-
|
|
70573
|
-
|
|
70574
|
-
|
|
70575
|
-
|
|
70576
|
-
|
|
70577
|
-
|
|
70578
|
-
isLoading: d
|
|
70579
|
-
}
|
|
70580
|
-
),
|
|
70581
|
-
I && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
70582
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2 my-1 pt-2", children: [
|
|
70583
|
-
/* @__PURE__ */ jsx(Switch, { checked: E, onCheckedChange: R, id: "extrapolate-switch", "aria-label": "Toggle sales extrapolation" }),
|
|
70584
|
-
/* @__PURE__ */ jsx(Label$2, { htmlFor: "extrapolate-switch", children: "Extrapolate" })
|
|
70585
|
-
] }),
|
|
70586
|
-
E && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mt-1", children: "* Sales for the current month are projected, not actual." })
|
|
70587
|
-
] })
|
|
70588
|
-
] })
|
|
70589
|
-
] }),
|
|
70572
|
+
/* @__PURE__ */ jsx(
|
|
70573
|
+
SalesChart,
|
|
70574
|
+
{
|
|
70575
|
+
salesData: (l == null ? void 0 : l.SalesStatistics) ?? [],
|
|
70576
|
+
isLoading: d
|
|
70577
|
+
}
|
|
70578
|
+
),
|
|
70590
70579
|
/* @__PURE__ */ jsx(
|
|
70591
70580
|
ManufacturerResellerOrdersSection,
|
|
70592
70581
|
{
|
|
@@ -70599,7 +70588,7 @@ function ManufacturerOverviewPage({
|
|
|
70599
70588
|
manufacturer: l,
|
|
70600
70589
|
readonly: t,
|
|
70601
70590
|
isLoading: d,
|
|
70602
|
-
onUnsavedChanges: (
|
|
70591
|
+
onUnsavedChanges: (I) => S("publicInfo", { hasUnsavedChanges: I })
|
|
70603
70592
|
}
|
|
70604
70593
|
),
|
|
70605
70594
|
n && /* @__PURE__ */ jsx(
|
|
@@ -70616,7 +70605,7 @@ function ManufacturerOverviewPage({
|
|
|
70616
70605
|
manufacturer: l,
|
|
70617
70606
|
readonly: t,
|
|
70618
70607
|
isLoading: d,
|
|
70619
|
-
onUnsavedChanges: (
|
|
70608
|
+
onUnsavedChanges: (I) => S("billingInfo", { hasUnsavedChanges: I })
|
|
70620
70609
|
}
|
|
70621
70610
|
),
|
|
70622
70611
|
n && /* @__PURE__ */ jsx(
|
|
@@ -70625,7 +70614,7 @@ function ManufacturerOverviewPage({
|
|
|
70625
70614
|
manufacturer: l,
|
|
70626
70615
|
readonly: t,
|
|
70627
70616
|
isLoading: d,
|
|
70628
|
-
onUnsavedChanges: (
|
|
70617
|
+
onUnsavedChanges: (I) => S("qualifications", { hasUnsavedChanges: I })
|
|
70629
70618
|
}
|
|
70630
70619
|
)
|
|
70631
70620
|
] }),
|
|
@@ -1055,4 +1055,4 @@ $10 with opportunities under $1,000`:e==="D"?"$15 under $1,500":e==="E"?"Full sh
|
|
|
1055
1055
|
* LICENSE.md file in the root directory of this source tree.
|
|
1056
1056
|
*
|
|
1057
1057
|
* @license MIT
|
|
1058
|
-
*/function flexRender(e,t){return e?isReactComponent(e)?React__namespace.createElement(e,t):e:null}function isReactComponent(e){return isClassComponent(e)||typeof e=="function"||isExoticComponent(e)}function isClassComponent(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function isExoticComponent(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function useReactTable(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=React__namespace.useState(()=>({current:createTable(t)})),[o,l]=React__namespace.useState(()=>n.current.initialState);return n.current.setOptions(d=>({...d,...e,state:{...o,...e.state},onStateChange:f=>{l(f),e.onStateChange==null||e.onStateChange(f)}})),n.current}function DataTable({columns:e,data:t,uniqueValues:n}){var E;const[o,l]=React.useState([]),[d,f]=React.useState([]),[g,b]=React.useState({pageIndex:0,pageSize:10}),[_,S]=React.useState(null),R=useReactTable({data:t,columns:e,getCoreRowModel:getCoreRowModel(),onSortingChange:l,getSortedRowModel:getSortedRowModel(),onColumnFiltersChange:f,getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),onPaginationChange:b,state:{sorting:o,columnFilters:d,pagination:g}}),C=(I,j)=>{I.toggleSorting(j),S(null)};return jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs(ScrollArea,{className:"rounded-md border",children:[jsxRuntime.jsxs(Table,{children:[jsxRuntime.jsx(TableHeader,{children:R.getHeaderGroups().map(I=>jsxRuntime.jsx(TableRow,{children:I.headers.map(j=>{var A;return jsxRuntime.jsx(TableHead,{children:j.isPlaceholder?null:j.column.getCanSort()||j.column.getCanFilter()?jsxRuntime.jsxs(Popover,{open:_===j.id,onOpenChange:O=>S(O?j.id:null),children:[jsxRuntime.jsx(PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button,{variant:"ghost",className:"pl-0",children:[flexRender(j.column.columnDef.header,j.getContext()),j.column.getIsFiltered()?jsxRuntime.jsx(Filter,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="asc"?jsxRuntime.jsx(ArrowUp,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="desc"?jsxRuntime.jsx(ArrowDown,{className:"ml-2 h-4 w-4"}):jsxRuntime.jsx(ArrowUpDown,{className:"ml-2 h-4 w-4"})]})}),jsxRuntime.jsx(PopoverContent,{className:"w-56",children:jsxRuntime.jsxs("div",{className:"space-y-2",children:[j.column.getCanSort()&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{variant:"ghost",className:"w-full justify-start",onClick:()=>C(j.column,!1),children:[jsxRuntime.jsx(ArrowUp,{className:"mr-2 h-4 w-4"}),"Sort Ascending"]}),jsxRuntime.jsxs(Button,{variant:"ghost",className:"w-full justify-start",onClick:()=>C(j.column,!0),children:[jsxRuntime.jsx(ArrowDown,{className:"mr-2 h-4 w-4"}),"Sort Descending"]})]}),j.column.getCanFilter()&&jsxRuntime.jsx("div",{className:"px-2 py-1",children:n[j.column.id]?jsxRuntime.jsxs(Select,{onValueChange:O=>j.column.setFilterValue(O==="all"?void 0:[O]),children:[jsxRuntime.jsx(SelectTrigger,{children:jsxRuntime.jsx(SelectValue,{placeholder:`Filter ${j.column.columnDef.header}...`})}),jsxRuntime.jsxs(SelectContent,{children:[jsxRuntime.jsx(SelectItem,{value:"all",children:"All"}),(A=n[j.column.id])==null?void 0:A.map(O=>jsxRuntime.jsx(SelectItem,{value:O||"empty",children:O||"(Empty)"},O))]})]}):jsxRuntime.jsx(Input,{placeholder:`Filter ${j.column.columnDef.header}...`,value:j.column.getFilterValue()??"",onChange:O=>j.column.setFilterValue(O.target.value),className:"w-full"})})]})})]}):jsxRuntime.jsx("div",{className:"py-2 px-4",children:flexRender(j.column.columnDef.header,j.getContext())})},j.id)})},I.id))}),jsxRuntime.jsx(TableBody,{children:(E=R.getRowModel().rows)!=null&&E.length?R.getRowModel().rows.map(I=>jsxRuntime.jsx(TableRow,{"data-state":I.getIsSelected()&&"selected",children:I.getVisibleCells().map(j=>jsxRuntime.jsx(TableCell,{children:flexRender(j.column.columnDef.cell,j.getContext())},j.id))},I.id)):jsxRuntime.jsx(TableRow,{children:jsxRuntime.jsx(TableCell,{colSpan:e.length,className:"h-24 text-center",children:"No results."})})})]}),jsxRuntime.jsx(ScrollBar,{orientation:"horizontal"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"Rows per page"}),jsxRuntime.jsxs(Select,{value:`${R.getState().pagination.pageSize}`,onValueChange:I=>{R.setPageSize(Number(I))},children:[jsxRuntime.jsx(SelectTrigger,{className:"h-8 w-[70px]",children:jsxRuntime.jsx(SelectValue,{placeholder:R.getState().pagination.pageSize})}),jsxRuntime.jsx(SelectContent,{side:"top",children:[10,20,30,40,50].map(I=>jsxRuntime.jsx(SelectItem,{value:`${I}`,children:I},I))})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsxs(Button,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>R.setPageIndex(0),disabled:!R.getCanPreviousPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to first page"}),jsxRuntime.jsx(ChevronsLeft,{className:"h-4 w-4"})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>R.previousPage(),disabled:!R.getCanPreviousPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to previous page"}),jsxRuntime.jsx(ChevronLeft,{className:"h-4 w-4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"Page"}),jsxRuntime.jsx("span",{className:"text-sm font-medium",children:R.getState().pagination.pageIndex+1}),jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"of"}),jsxRuntime.jsx("span",{className:"text-sm font-medium",children:R.getPageCount()})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>R.nextPage(),disabled:!R.getCanNextPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to next page"}),jsxRuntime.jsx(ChevronRight,{className:"h-4 w-4"})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>R.setPageIndex(R.getPageCount()-1),disabled:!R.getCanNextPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to last page"}),jsxRuntime.jsx(ChevronsRight,{className:"h-4 w-4"})]})]})]})]})}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.jsx("div",{className:"flex gap-2",children:e.map(o=>jsxRuntime.jsx(Button,{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},o.CategoryCode))})})})}function ManufacturerProducts({applicationId:e,manufacturer:t,shopifyHostName:n}){var Q,F,V,te;const[o]=usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[l]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[d,f]=React.useState(((F=(Q=t.Categories)==null?void 0:Q[0])==null?void 0:F.CategoryCode)||""),[g,b]=React.useState(null),[_,S]=React.useState(!1),[R,C]=React.useState(!1),{toast:E}=useToast(),{data:I,isLoading:j,isFetching:A}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:e,manufacturerId:t.ManufacturerId,categoryCode:d??""},{skip:!t.ManufacturerId||!d}),O=async ie=>{try{b(ie),await o({routeResellerId:e,randmarSku:ie,shopifyHostName:n}).unwrap()&&E({title:"Success",description:"Product synced to Shopify successfully",variant:"success"})}catch(ae){console.error("Error syncing to Shopify:",ae),E({title:"Error",description:"Error syncing product to Shopify.",variant:"destructive"})}finally{b(null)}},q=async()=>{try{S(!0),C(!1),await l({routeResellerId:e,manufacturerId:t.ManufacturerId??"",categoryCode:d,shopifyHostName:n}).unwrap()&&E({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(ie){console.error("Error syncing to Shopify:",ie),E({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{S(!1)}},z=()=>{var ie,ae;return((ae=(ie=t.Categories)==null?void 0:ie.find(oe=>oe.CategoryCode===d))==null?void 0:ae.CategoryName)||d};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ManufacturerCategories,{categories:t.Categories||[],activeCategory:d,onSelectCategory:f}),n&&((V=t.Categories)==null?void 0:V.findIndex(ie=>ie.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:R,onOpenChange:C,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 mb-4",disabled:_,children:_?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(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 "',z(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:q,disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4 mb-4",children:j||A?Array.from({length:4}).map((ie,ae)=>jsxRuntime.jsx(ProductCard,{},ae)):I!=null&&I.Products&&(I==null?void 0:I.Products.length)>0?(te=I==null?void 0:I.Products)==null?void 0:te.map(ie=>jsxRuntime.jsx(ProductCard,{applicationId:e,item:ie,viewProductLink:`/${e}/Product/${ie.RandmarSKU}`,syncToShopify:!!n,isSyncToShopifyActionLoading:g===ie.RandmarSKU,syncToShopifyAction:()=>ie.RandmarSKU&&O(ie.RandmarSKU)},ie.RandmarSKU)):jsxRuntime.jsxs(Alert,{variant:"warning",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."})]})})]})}function PartnerRelationshipPage({applicationId:e,partnerId:t,userEmail:n,shopifyHostName:o,isSuperAdmin:l}){var j,A,O;const{data:d,isLoading:f}=useGetV4PartnerByApplicationIdPartnerAndPartnerIdQuery({applicationId:e,partnerId:t,withSpecification:!0}),{toast:g}=useToast(),[b]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[_,S]=React.useState(!1),[R,C]=React.useState(!1),E=async()=>{try{S(!0),C(!1),await b({routeResellerId:e??"",manufacturerId:t??"",shopifyHostName:o}).unwrap()&&g({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(q){console.error("Error syncing to Shopify:",q),g({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{S(!1)}},I=()=>d!=null&&d.Reseller?"reseller-overview":d!=null&&d.Manufacturer?"manufacturer-overview":"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 md:grid-cols-2",children:[jsxRuntime.jsx(PartnerCard,{account:d,loading:f,withAbout:!0,withVoice:!1,action:" "}),jsxRuntime.jsxs("div",{className:"grid gap-4",children:[((d==null?void 0:d.Manufacturer)||f)&&jsxRuntime.jsx(ManufacturerCard,{manufacturer:d==null?void 0:d.Manufacturer,loading:f,mainAction:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(ManufacturerGetStartedButton,{applicationId:e,manufacturer:d==null?void 0:d.Manufacturer}),o&&((A=(j=d==null?void 0:d.Manufacturer)==null?void 0:j.Categories)==null?void 0:A.findIndex(q=>q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:R,onOpenChange:C,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 ml-2",disabled:_,children:_?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 "',(O=d==null?void 0:d.Manufacturer)==null?void 0:O.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:E,disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(ResellerCard,{reseller:d==null?void 0:d.Reseller,loading:f})]})]}),((d==null?void 0:d.Reseller)||(d==null?void 0:d.Manufacturer))&&!f&&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:[(d==null?void 0:d.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"}),(d==null?void 0:d.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"}),(d==null?void 0:d.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"})]}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsContent,{value:"reseller-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ResellerOverview,{readonly:!0,appID:d.ApplicationId||"",reseller:d==null?void 0:d.Reseller,userEmail:n,isSuperAdmin:l,withoutReports:!0})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"manufacturer-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerOverviewPage,{readonly:!0,applicationId:d.ApplicationId||"",userEmail:n})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"products",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerProducts,{applicationId:e,manufacturer:d.Manufacturer,shopifyHostName:o})})})]})}),f&&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"})})]})}function ManufacturerBillingInfoSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState({}),b=React.useMemo(()=>({accountsPayableRep:(e==null?void 0:e.ContactName)??"",representativeEmail:(e==null?void 0:e.RepresentativeEmail)??"",phone:(e==null?void 0:e.Phone)??"",creditLimit:(e==null?void 0:e.CreditLimit)??0,terms:(e==null?void 0:e.Terms)??""}),[e]),{register:_,handleSubmit:S,reset:R,watch:C,formState:{errors:E,isSubmitting:I}}=useForm({defaultValues:b}),j=C(),A=React.useCallback(()=>t||!f?!1:JSON.stringify(j)!==JSON.stringify(f),[t,j,f]);React.useEffect(()=>{o&&o(A())},[A,o]),React.useEffect(()=>{e&&(R(b),g(b))},[e,R,b]);const O=async q=>{if(t)return;let z=!0,Q=!1;const F=[{key:"accountsPayableRep",apiKey:"ContactName",value:q.accountsPayableRep},{key:"representativeEmail",apiKey:"RepresentativeEmail",value:q.representativeEmail},{key:"phone",apiKey:"Phone",value:q.phone},{key:"terms",apiKey:"Terms",value:q.terms}];for(const V of F){const te=V.value,ie=e==null?void 0:e[V.apiKey];if(te!==ie&&te!==void 0){Q=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:V.apiKey,newValue:String(te)}).unwrap()||(z=!1,console.error(`Failed to update ${V.apiKey}`))}catch(ae){console.error(`Error updating ${V.apiKey}:`,ae),z=!1}}}z&&Q?(l({title:"Billing info",description:"Information updated successfully",variant:"success"}),g({...q}),o&&o(!1)):z?Q||l({title:"No changes",description:"No changes were made to the information.",variant:"info"}):l({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Billing, Credit, & Rebates"})}),jsxRuntime.jsx(CardContent,{children:n?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-48"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-36"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]}),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-16"}),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-16"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs("form",{onSubmit:S(O),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$2,{className:"text-sm font-medium leading-none",htmlFor:"accountsPayableRep",children:"Accounts Payable Representative"}),jsxRuntime.jsx(Input,{id:"accountsPayableRep",placeholder:"John Doe",..._("accountsPayableRep"),readOnly:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"representativeEmail",children:"Representative Email"}),jsxRuntime.jsx(Input,{id:"representativeEmail",placeholder:"john.doe@company.com",..._("representativeEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),readOnly:t}),E.representativeEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.representativeEmail.message})]})]}),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$2,{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone"}),jsxRuntime.jsx(Input,{id:"phone",placeholder:"(555) 123-4567",..._("phone"),readOnly:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"creditLimit",children:"Credit Limit"}),jsxRuntime.jsx("div",{className:"p-2 border rounded-md bg-gray-100",children:jsxRuntime.jsx(FormattedNumber,{value:(e==null?void 0:e.CreditLimit)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"terms",children:"Terms"}),jsxRuntime.jsx(Input,{id:"terms",placeholder:"NET 30 DAYS",..._("terms"),readOnly:!0})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I,className:"w-full sm:w-auto",children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function OpenToWorkSection({manufacturer:e,readonly:t=!1,isLoading:n}){const{toast:o}=useToast(),[l]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),d=React.useMemo(()=>({openToWork:(e==null?void 0:e.OpenToWork)??!1}),[e]),{reset:f,watch:g}=useForm({defaultValues:d});React.useEffect(()=>{e&&f(d)},[e,f,d]);const b=async _=>{if(!t)try{await l({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:"OpenToWork",newValue:_?"true":"false"}).unwrap()&&o({title:"Open to work info",description:"Information updated successfully",variant:"success"})}catch(S){console.error("Error updating",S)}};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Open to Work with Resellers"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})}):jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Resellers will be introducing their business, and communicating opportunities for your Brand through Randmar."}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"You'll engage directly with resellers, allow them to learn about your product lines, and grow your business faster."}),jsxRuntime.jsx("br",{}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Switch,{id:"openToWork",checked:g("openToWork"),onCheckedChange:_=>b(_),disabled:t}),jsxRuntime.jsx(Label$2,{htmlFor:"openToWork",children:"Open to work with Resellers"})]})]})})]})}const tagSuggestions=["Arts and Crafts","Cleaning Solutions","Clothing","Electronics","Generic Compatible Toner","Ink","Luggage and Bags","Miscellaneous","Networking Devices","Paper Products","Printers","Printing Supplies","Toner"];function ManufacturerPublicInfoSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState([]),[b,_]=React.useState({}),S=React.useMemo(()=>({publicName:(e==null?void 0:e.PublicName)??"",website:(e==null?void 0:e.Website)??"",customerServiceEmail:(e==null?void 0:e.PublicEmail)??"",publicResources:(e==null?void 0:e.PublicResourcesLink)??""}),[e]),{register:R,handleSubmit:C,reset:E,watch:I,formState:{errors:j,isSubmitting:A}}=useForm({defaultValues:S}),O=I(),q=React.useCallback(()=>t||!b?!1:JSON.stringify(O)!==JSON.stringify(b),[t,O,b]);React.useEffect(()=>{o&&o(q())},[q,o]),React.useEffect(()=>{e&&(E(S),g(e.Tags?e.Tags.split(",").map(V=>V.trim()):[]),_(S))},[e,E,S]);const z=async V=>{if(t)return;let te=!0,ie=!1;const ae=[{key:"publicName",apiKey:"PublicName",value:V.publicName},{key:"website",apiKey:"Website",value:V.website},{key:"manufacturerCategories",apiKey:"Tags",value:f.join(", ")},{key:"customerServiceEmail",apiKey:"PublicEmail",value:V.customerServiceEmail},{key:"publicResources",apiKey:"PublicResourcesLink",value:V.publicResources}];for(const oe of ae){const se=oe.value,ge=e==null?void 0:e[oe.apiKey],Ae=typeof ge=="boolean"?String(ge):ge;if(se!==Ae&&se!==void 0){ie=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:oe.apiKey,newValue:String(se)}).unwrap()||(te=!1)}catch(je){console.error(`Error updating ${oe.apiKey}:`,je),te=!1}}}te&&ie?(l({title:"Public info",description:"Information updated successfully",variant:"success"}),_({...V}),o&&o(!1)):te||l({title:"Update error",description:"Failed to update",variant:"destructive"})},Q=V=>!V||V.trim()==="",F=V=>{g(V)};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Public Information"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),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:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-10"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-48"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),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.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(Q(I("publicName"))||Q(I("website"))||Q(I("customerServiceEmail")))&&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 Resellers."})]}),jsxRuntime.jsxs("form",{onSubmit:C(z),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"publicName",children:"Public Manufacturer Name *"}),jsxRuntime.jsx(Input,{id:"publicName",placeholder:"Company Name",...R("publicName",{}),className:Q(I("publicName"))?"input-error-indicator":"",readOnly:t}),j.publicName&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.publicName.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),jsxRuntime.jsx(Input,{id:"website",placeholder:"https://company.com",...R("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:Q(I("website"))?"input-error-indicator":"",readOnly:t}),j.website&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.website.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"manufacturerCategories",children:"Manufacturer Categories"}),jsxRuntime.jsx(MultiSelect,{options:tagSuggestions,selected:f,onChange:F,placeholder:"Select or type categories...",disabled:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"customerServiceEmail",children:"Customer Service Email *"}),jsxRuntime.jsx(Input,{id:"customerServiceEmail",placeholder:"support@company.com",...R("customerServiceEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:Q(I("customerServiceEmail"))?"input-error-indicator":"",readOnly:t}),j.customerServiceEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.customerServiceEmail.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"publicResources",children:"Public Resources"}),jsxRuntime.jsx(Input,{id:"publicResources",placeholder:"https://resources.company.com",...R("publicResources"),readOnly:t})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:A,className:"w-full sm:w-auto",children:A?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})]})})]})}function ManufacturerQualificationsSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState({}),b=React.useMemo(()=>({partnerPortal:(e==null?void 0:e.PartnerPortal)??"",partnerRegistrationLink:(e==null?void 0:e.PartnerRegistrationLink)??""}),[e]),{register:_,handleSubmit:S,reset:R,watch:C,formState:{errors:E,isSubmitting:I}}=useForm({defaultValues:b}),j=C(),A=React.useCallback(()=>t||!f?!1:JSON.stringify(j)!==JSON.stringify(f),[t,j,f]);React.useEffect(()=>{o&&o(A())},[A,o]),React.useEffect(()=>{e&&(R(b),g(b))},[e,R,b]);const O=async z=>{if(t)return!1;let Q=!0,F=!1;const V=[{key:"partnerPortal",apiKey:"PartnerPortal",value:z.partnerPortal},{key:"partnerRegistrationLink",apiKey:"PartnerRegistrationLink",value:z.partnerRegistrationLink}];for(const te of V){const ie=te.value,ae=e==null?void 0:e[te.apiKey];if(ie!==ae&&ie!==void 0){F=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:te.apiKey,newValue:String(ie)}).unwrap()||(Q=!1,console.error(`Failed to update ${te.apiKey}`))}catch(oe){console.error(`Error updating ${te.apiKey}:`,oe),Q=!1}}}Q&&F?(l({title:"Qualifications info",description:"Information updated successfully",variant:"success"}),g({...z}),o&&o(!1)):Q?F||l({title:"No changes",description:"No changes were made to the information.",variant:"info"}):l({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})},q=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?(\?[^\s#]*)??(#[^\s]*)?$/i;return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Qualifications"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsxs("div",{className:"space-y-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-48"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs("form",{onSubmit:S(O),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"partnerPortal",children:"Partner Portal"}),jsxRuntime.jsx(Input,{id:"partnerPortal",placeholder:"https://partner.example.com",..._("partnerPortal",{pattern:{value:q,message:"Invalid URL format"}}),readOnly:t}),E.partnerPortal&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.partnerPortal.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"partnerRegistrationLink",children:"Partner Registration Link"}),jsxRuntime.jsx(Input,{id:"partnerRegistrationLink",placeholder:"https://register.example.com",..._("partnerRegistrationLink",{pattern:{value:q,message:"Invalid URL format"}}),readOnly:t}),E.partnerRegistrationLink&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.partnerRegistrationLink.message})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I,className:"w-full sm:w-auto",children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function ManufacturerReportsSection({manufacturerId:e,userEmail:t,isLoading:n}){const{toast:o}=useToast(),[l,{isLoading:d}]=usePostV4ManufacturerByRouteManufacturerIdDocumentAndDocumentNumberEmailMutation(),[f,g]=React.useState(null),[b,_]=React.useState(t),[S,R]=React.useState(!1),C=[{name:"Orders & Sales",reports:[{id:"OpenOrders",title:"Open Orders Report",description:"The Open Orders Report provides a snapshot of active orders, aiding your business in efficiently tracking and fulfilling customer demands.",icon:FileText},{id:"Sales",title:"Sales Report",description:"Summary of your company's sales activity over a certain period, detailing total sales and helping identifying trends, successes, and areas needing improvement.",icon:ChartNoAxesColumnIncreasing}]},{name:"Purchase Orders",reports:[{id:"PurchasedOrders",title:"Open Purchase Orders Report",description:"The Open Purchase Orders Report provides a snapshot of Randmar's active orders, aiding your business in efficiently tracking and fulfilling Randmar's inventory demands.",icon:ShoppingCart},{id:"Reorder",title:"Reordering Report",description:"The Reordering Report provides a snapshot of all part numbers auto-reordering statuses. Aiding your understanding of what will be automatically reordered by our system or not once the inventory reaches low numbers.",icon:ClipboardList}]},{name:"Inventory",reports:[{id:"Inventory",title:"Inventory Report",description:"Detailed document outlining the quantity, type, and value of products Randmar has on hand. It aids in managing stock levels, identifying shortages or surpluses, and informing purchasing decisions.",icon:Package},{id:"Products",title:"Products Report",description:"Detailed document outlining all your products properties. It provides a comprehensive overview of essential information and insights that help you make informed decisions.",icon:ClipboardList}]}],E=async j=>{g(j),R(!0)},I=async()=>{if(!(!f||!e))try{await l({routeManufacturerId:e,documentNumber:f.id,emailAddress:b}).unwrap(),o({title:"Report requested",description:`The ${f.title} will be sent to ${b} shortly.`,variant:"success"}),R(!1),_("")}catch(j){console.error("Error requesting report:",j),o({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}};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 Open Orders & Sales Report, to your Inventory Reports."})]}),jsxRuntime.jsx(CardContent,{className:"space-y-6",children:n?jsxRuntime.jsx(jsxRuntime.Fragment,{children:[1,2,3].map(j=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-48"}),[1,2].map(A=>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"})]},A))]},j))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:C.map(j=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:j.name}),j.reports.map(A=>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(A.icon,{className:"h-5 w-5 text-primary"})}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("h4",{className:"font-semibold text-sm",children:A.title}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:A.description})]}),jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>E(A),children:[jsxRuntime.jsx(Download,{className:"h-4 w-4"}),"Request"]})]},A.id))]},j.name))})}),jsxRuntime.jsx(Dialog,{open:S,onOpenChange:R,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsxs(DialogTitle,{children:["Request ",f==null?void 0:f.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:b,onChange:j=>_(j.target.value),placeholder:"your@email.com",className:"mt-2"})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>R(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{onClick:I,disabled:!b||d,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function ManufacturerResellerOrdersSection({manufacturerId:e}){const{data:t,isLoading:n,isError:o}=useGetV4ManufacturerByRouteManufacturerIdDocumentsActiveOrderDetailsQuery({routeManufacturerId:e}),d=(()=>{if(!t)return{all:{orders:0,amount:0},processing:{orders:0,amount:0},shipped:{orders:0,amount:0},delayed:{orders:0,amount:0}};const g=t.filter(z=>z.DocumentType==="Order"),b=t.filter(z=>z.DocumentType==="Shipment"),_=g.filter(z=>z.WarehouseCode!=="3PLE"),S=_.reduce((z,Q)=>z+(Q.Quantity||0),0),R=_.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),C=g.filter(z=>z.WarehouseCode==="3PLE"),E=C.reduce((z,Q)=>z+(Q.Quantity||0),0),I=C.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),j=b.length,A=b.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),O=S+E+j,q=R+I+A;return{all:{orders:O,amount:q},processing:{orders:S,amount:R},shipped:{orders:j,amount:A},delayed:{orders:E,amount:I}}})(),f=[{name:"All",icon:Package,color:"bg-blue-500",orders:d.all.orders,amount:d.all.amount},{name:"Processing",icon:RefreshCcw,color:"bg-yellow-500",orders:d.processing.orders,amount:d.processing.amount},{name:"Shipped",icon:Truck,color:"bg-green-500",orders:d.shipped.orders,amount:d.shipped.amount},{name:"Delayed",icon:CircleAlert,color:"bg-red-500",orders:d.delayed.orders,amount:d.delayed.amount}];return n?jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40 mb-4"}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(g=>jsxRuntime.jsx(Skeleton,{className:"h-32 w-full"},g))})]})]}):o?jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"Failed to load reseller orders. Please try again later."})]})})]}):jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsxs("div",{className:"flex items-center mb-4",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Active Orders:"}),jsxRuntime.jsx("span",{className:"ml-2 font-bold",children:d.all.orders})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3.5",children:f.map(g=>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:`${g.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:g.name}),jsxRuntime.jsx("div",{className:`${g.color} bg-opacity-90 p-2 rounded-full`,children:jsxRuntime.jsx(g.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:g.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:g.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},g.name))})]})]})}function ManufacturerOverviewPage({applicationId:e,readonly:t,withReports:n,userEmail:o}){const{data:l,isLoading:d,isError:f}=useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:e}),[g,b]=React.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),_=React.useCallback(()=>t?!1:g.publicInfo.hasUnsavedChanges||g.qualifications.hasUnsavedChanges||g.billingInfo.hasUnsavedChanges,[t,g]),S=React.useCallback((j,A)=>{b(O=>{var q;return((q=O[j])==null?void 0:q.hasUnsavedChanges)!==A.hasUnsavedChanges?(console.log(`Updating form state for ${j}:`,A.hasUnsavedChanges),{...O,[j]:A}):O})},[]),{NavigationGuardDialog:R}=useRouterNavigationGuard(_),[C,E]=React.useState(!0),I=!d&&!!(l!=null&&l.SalesStatistics)&&l.SalesStatistics.length>0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[f?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:l==null?void 0:l.FiscalYearMonthStart,salesData:l==null?void 0:l.SalesData,isLoading:d}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Sales"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsx(SalesChart,{salesData:(l==null?void 0:l.SalesStatistics)??[],isLoading:d}),I&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 my-1 pt-2",children:[jsxRuntime.jsx(Switch,{checked:C,onCheckedChange:E,id:"extrapolate-switch","aria-label":"Toggle sales extrapolation"}),jsxRuntime.jsx(Label$2,{htmlFor:"extrapolate-switch",children:"Extrapolate"})]}),C&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"* Sales for the current month are projected, not actual."})]})]})]}),jsxRuntime.jsx(ManufacturerResellerOrdersSection,{manufacturerId:e}),n&&jsxRuntime.jsx(ManufacturerPublicInfoSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:j=>S("publicInfo",{hasUnsavedChanges:j})}),n&&jsxRuntime.jsx(OpenToWorkSection,{manufacturer:l,readonly:t,isLoading:d}),n&&jsxRuntime.jsx(ManufacturerBillingInfoSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:j=>S("billingInfo",{hasUnsavedChanges:j})}),n&&jsxRuntime.jsx(ManufacturerQualificationsSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:j=>S("qualifications",{hasUnsavedChanges:j})})]}),n&&jsxRuntime.jsx(ManufacturerReportsSection,{manufacturerId:e,userEmail:o,isLoading:d})]}),jsxRuntime.jsx(R,{})]})}exports.ActiveOrdersCard=ActiveOrdersCard,exports.AiGeneratedContent=AiGeneratedContent,exports.Alert=Alert,exports.AlertDescription=AlertDescription,exports.AlertTitle=AlertTitle,exports.ApiKeyProvider=ApiKeyProvider,exports.AreaChart=AreaChart,exports.Avatar=Avatar,exports.AvatarFallback=AvatarFallback,exports.AvatarFooter=AvatarFooter,exports.AvatarImage=AvatarImage,exports.Badge=Badge,exports.Button=Button,exports.Card=Card,exports.CardContent=CardContent,exports.CardDescription=CardDescription,exports.CardFooter=CardFooter,exports.CardHeader=CardHeader,exports.CardTitle=CardTitle,exports.ChatLayout=ChatLayout,exports.ChatProvider=ChatProvider,exports.Checkbox=Checkbox,exports.Command=Command,exports.CommandDialog=CommandDialog,exports.CommandEmpty=CommandEmpty,exports.CommandGroup=CommandGroup,exports.CommandInput=CommandInput,exports.CommandItem=CommandItem,exports.CommandList=CommandList,exports.CommandSeparator=CommandSeparator,exports.CommandShortcut=CommandShortcut,exports.CountryFlag=CountryFlag,exports.DataTable=DataTable,exports.Dialog=Dialog,exports.DialogClose=DialogClose,exports.DialogContent=DialogContent,exports.DialogDescription=DialogDescription,exports.DialogFooter=DialogFooter,exports.DialogHeader=DialogHeader,exports.DialogOverlay=DialogOverlay,exports.DialogPortal=DialogPortal,exports.DialogTitle=DialogTitle,exports.DialogTrigger=DialogTrigger,exports.DropdownMenu=DropdownMenu,exports.DropdownMenuCheckboxItem=DropdownMenuCheckboxItem,exports.DropdownMenuContent=DropdownMenuContent,exports.DropdownMenuGroup=DropdownMenuGroup,exports.DropdownMenuItem=DropdownMenuItem,exports.DropdownMenuLabel=DropdownMenuLabel,exports.DropdownMenuPortal=DropdownMenuPortal,exports.DropdownMenuRadioGroup=DropdownMenuRadioGroup,exports.DropdownMenuRadioItem=DropdownMenuRadioItem,exports.DropdownMenuSeparator=DropdownMenuSeparator,exports.DropdownMenuShortcut=DropdownMenuShortcut,exports.DropdownMenuSub=DropdownMenuSub,exports.DropdownMenuSubContent=DropdownMenuSubContent,exports.DropdownMenuSubTrigger=DropdownMenuSubTrigger,exports.DropdownMenuTrigger=DropdownMenuTrigger,exports.ExploreManufacturers=ExploreManufacturers,exports.GeneralDocumentCard=GeneralDocumentCard,exports.Input=Input,exports.InputOTP=InputOTP,exports.InputOTPGroup=InputOTPGroup,exports.InputOTPSeparator=InputOTPSeparator,exports.InputOTPSlot=InputOTPSlot,exports.Label=Label$2,exports.Layout=Layout,exports.ManufacturerCard=ManufacturerCard,exports.ManufacturerGetStartedButton=ManufacturerGetStartedButton,exports.ManufacturerOverviewPage=ManufacturerOverviewPage,exports.ManufacturerReorderingCard=ManufacturerReorderingCard,exports.MultiSelect=MultiSelect,exports.Navbar=Navbar,exports.PartnerCard=PartnerCard,exports.PartnerRelationshipPage=PartnerRelationshipPage,exports.Popover=Popover,exports.PopoverAnchor=PopoverAnchor,exports.PopoverContent=PopoverContent,exports.PopoverTrigger=PopoverTrigger,exports.Preloader=Preloader,exports.ProductCard=ProductCard,exports.ProductImage=ProductImage,exports.ProductInventoryGrid=ProductInventoryGrid,exports.RadioGroup=RadioGroup$1,exports.RadioGroupItem=RadioGroupItem,exports.ResellerBillingOverviewCard=ResellerBillingOverviewCard,exports.ResellerCard=ResellerCard,exports.ResellerOverview=ResellerOverview,exports.ResellerQualificationsCard=ResellerQualificationsCard,exports.SalesOverviewCard=SalesOverviewCard,exports.ScrollArea=ScrollArea,exports.ScrollBar=ScrollBar,exports.Select=Select,exports.SelectContent=SelectContent,exports.SelectGroup=SelectGroup,exports.SelectItem=SelectItem,exports.SelectLabel=SelectLabel,exports.SelectScrollDownButton=SelectScrollDownButton,exports.SelectScrollUpButton=SelectScrollUpButton,exports.SelectTrigger=SelectTrigger,exports.SelectValue=SelectValue,exports.Separator=Separator$1,exports.Sheet=Sheet,exports.SheetClose=SheetClose,exports.SheetContent=SheetContent,exports.SheetDescription=SheetDescription,exports.SheetFooter=SheetFooter,exports.SheetHeader=SheetHeader,exports.SheetOverlay=SheetOverlay,exports.SheetPortal=SheetPortal,exports.SheetTitle=SheetTitle,exports.SheetTrigger=SheetTrigger,exports.Sidebar=Sidebar,exports.SidebarContent=SidebarContent,exports.SidebarFooter=SidebarFooter,exports.SidebarGroup=SidebarGroup,exports.SidebarGroupAction=SidebarGroupAction,exports.SidebarGroupContent=SidebarGroupContent,exports.SidebarGroupLabel=SidebarGroupLabel,exports.SidebarHeader=SidebarHeader,exports.SidebarInput=SidebarInput,exports.SidebarInset=SidebarInset,exports.SidebarMenu=SidebarMenu,exports.SidebarMenuAction=SidebarMenuAction,exports.SidebarMenuBadge=SidebarMenuBadge,exports.SidebarMenuButton=SidebarMenuButton,exports.SidebarMenuItem=SidebarMenuItem,exports.SidebarMenuSkeleton=SidebarMenuSkeleton,exports.SidebarMenuSub=SidebarMenuSub,exports.SidebarMenuSubButton=SidebarMenuSubButton,exports.SidebarMenuSubItem=SidebarMenuSubItem,exports.SidebarProvider=SidebarProvider,exports.SidebarRail=SidebarRail,exports.SidebarSeparator=SidebarSeparator,exports.SidebarTrigger=SidebarTrigger,exports.Skeleton=Skeleton,exports.Switch=Switch,exports.Table=Table,exports.TableBody=TableBody,exports.TableCaption=TableCaption,exports.TableCell=TableCell,exports.TableFooter=TableFooter,exports.TableHead=TableHead,exports.TableHeader=TableHeader,exports.TableRow=TableRow,exports.Tabs=Tabs,exports.TabsContent=TabsContent,exports.TabsList=TabsList,exports.TabsTrigger=TabsTrigger,exports.Textarea=Textarea,exports.Toast=Toast,exports.ToastAction=ToastAction,exports.ToastClose=ToastClose,exports.ToastDescription=ToastDescription,exports.ToastProvider=ToastProvider,exports.ToastTitle=ToastTitle,exports.ToastViewport=ToastViewport,exports.Toaster=Toaster,exports.Tooltip=Tooltip$1,exports.TooltipContent=TooltipContent,exports.TooltipProvider=TooltipProvider,exports.TooltipTrigger=TooltipTrigger,exports.Topbar=Topbar,exports.badgeVariants=badgeVariants,exports.buttonVariants=buttonVariants,exports.toast=toast,exports.useApiKey=useApiKey,exports.useChat=useChat,exports.useIsMobile=useIsMobile,exports.useSidebar=useSidebar,exports.useToast=useToast,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
1058
|
+
*/function flexRender(e,t){return e?isReactComponent(e)?React__namespace.createElement(e,t):e:null}function isReactComponent(e){return isClassComponent(e)||typeof e=="function"||isExoticComponent(e)}function isClassComponent(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function isExoticComponent(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function useReactTable(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=React__namespace.useState(()=>({current:createTable(t)})),[o,l]=React__namespace.useState(()=>n.current.initialState);return n.current.setOptions(d=>({...d,...e,state:{...o,...e.state},onStateChange:f=>{l(f),e.onStateChange==null||e.onStateChange(f)}})),n.current}function DataTable({columns:e,data:t,uniqueValues:n}){var E;const[o,l]=React.useState([]),[d,f]=React.useState([]),[g,b]=React.useState({pageIndex:0,pageSize:10}),[_,S]=React.useState(null),R=useReactTable({data:t,columns:e,getCoreRowModel:getCoreRowModel(),onSortingChange:l,getSortedRowModel:getSortedRowModel(),onColumnFiltersChange:f,getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),onPaginationChange:b,state:{sorting:o,columnFilters:d,pagination:g}}),C=(I,j)=>{I.toggleSorting(j),S(null)};return jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs(ScrollArea,{className:"rounded-md border",children:[jsxRuntime.jsxs(Table,{children:[jsxRuntime.jsx(TableHeader,{children:R.getHeaderGroups().map(I=>jsxRuntime.jsx(TableRow,{children:I.headers.map(j=>{var A;return jsxRuntime.jsx(TableHead,{children:j.isPlaceholder?null:j.column.getCanSort()||j.column.getCanFilter()?jsxRuntime.jsxs(Popover,{open:_===j.id,onOpenChange:O=>S(O?j.id:null),children:[jsxRuntime.jsx(PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button,{variant:"ghost",className:"pl-0",children:[flexRender(j.column.columnDef.header,j.getContext()),j.column.getIsFiltered()?jsxRuntime.jsx(Filter,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="asc"?jsxRuntime.jsx(ArrowUp,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="desc"?jsxRuntime.jsx(ArrowDown,{className:"ml-2 h-4 w-4"}):jsxRuntime.jsx(ArrowUpDown,{className:"ml-2 h-4 w-4"})]})}),jsxRuntime.jsx(PopoverContent,{className:"w-56",children:jsxRuntime.jsxs("div",{className:"space-y-2",children:[j.column.getCanSort()&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{variant:"ghost",className:"w-full justify-start",onClick:()=>C(j.column,!1),children:[jsxRuntime.jsx(ArrowUp,{className:"mr-2 h-4 w-4"}),"Sort Ascending"]}),jsxRuntime.jsxs(Button,{variant:"ghost",className:"w-full justify-start",onClick:()=>C(j.column,!0),children:[jsxRuntime.jsx(ArrowDown,{className:"mr-2 h-4 w-4"}),"Sort Descending"]})]}),j.column.getCanFilter()&&jsxRuntime.jsx("div",{className:"px-2 py-1",children:n[j.column.id]?jsxRuntime.jsxs(Select,{onValueChange:O=>j.column.setFilterValue(O==="all"?void 0:[O]),children:[jsxRuntime.jsx(SelectTrigger,{children:jsxRuntime.jsx(SelectValue,{placeholder:`Filter ${j.column.columnDef.header}...`})}),jsxRuntime.jsxs(SelectContent,{children:[jsxRuntime.jsx(SelectItem,{value:"all",children:"All"}),(A=n[j.column.id])==null?void 0:A.map(O=>jsxRuntime.jsx(SelectItem,{value:O||"empty",children:O||"(Empty)"},O))]})]}):jsxRuntime.jsx(Input,{placeholder:`Filter ${j.column.columnDef.header}...`,value:j.column.getFilterValue()??"",onChange:O=>j.column.setFilterValue(O.target.value),className:"w-full"})})]})})]}):jsxRuntime.jsx("div",{className:"py-2 px-4",children:flexRender(j.column.columnDef.header,j.getContext())})},j.id)})},I.id))}),jsxRuntime.jsx(TableBody,{children:(E=R.getRowModel().rows)!=null&&E.length?R.getRowModel().rows.map(I=>jsxRuntime.jsx(TableRow,{"data-state":I.getIsSelected()&&"selected",children:I.getVisibleCells().map(j=>jsxRuntime.jsx(TableCell,{children:flexRender(j.column.columnDef.cell,j.getContext())},j.id))},I.id)):jsxRuntime.jsx(TableRow,{children:jsxRuntime.jsx(TableCell,{colSpan:e.length,className:"h-24 text-center",children:"No results."})})})]}),jsxRuntime.jsx(ScrollBar,{orientation:"horizontal"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"Rows per page"}),jsxRuntime.jsxs(Select,{value:`${R.getState().pagination.pageSize}`,onValueChange:I=>{R.setPageSize(Number(I))},children:[jsxRuntime.jsx(SelectTrigger,{className:"h-8 w-[70px]",children:jsxRuntime.jsx(SelectValue,{placeholder:R.getState().pagination.pageSize})}),jsxRuntime.jsx(SelectContent,{side:"top",children:[10,20,30,40,50].map(I=>jsxRuntime.jsx(SelectItem,{value:`${I}`,children:I},I))})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsxs(Button,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>R.setPageIndex(0),disabled:!R.getCanPreviousPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to first page"}),jsxRuntime.jsx(ChevronsLeft,{className:"h-4 w-4"})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>R.previousPage(),disabled:!R.getCanPreviousPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to previous page"}),jsxRuntime.jsx(ChevronLeft,{className:"h-4 w-4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"Page"}),jsxRuntime.jsx("span",{className:"text-sm font-medium",children:R.getState().pagination.pageIndex+1}),jsxRuntime.jsx("p",{className:"text-sm font-medium",children:"of"}),jsxRuntime.jsx("span",{className:"text-sm font-medium",children:R.getPageCount()})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>R.nextPage(),disabled:!R.getCanNextPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to next page"}),jsxRuntime.jsx(ChevronRight,{className:"h-4 w-4"})]}),jsxRuntime.jsxs(Button,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>R.setPageIndex(R.getPageCount()-1),disabled:!R.getCanNextPage(),children:[jsxRuntime.jsx("span",{className:"sr-only",children:"Go to last page"}),jsxRuntime.jsx(ChevronsRight,{className:"h-4 w-4"})]})]})]})]})}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.jsx("div",{className:"flex gap-2",children:e.map(o=>jsxRuntime.jsx(Button,{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},o.CategoryCode))})})})}function ManufacturerProducts({applicationId:e,manufacturer:t,shopifyHostName:n}){var Q,F,V,te;const[o]=usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[l]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[d,f]=React.useState(((F=(Q=t.Categories)==null?void 0:Q[0])==null?void 0:F.CategoryCode)||""),[g,b]=React.useState(null),[_,S]=React.useState(!1),[R,C]=React.useState(!1),{toast:E}=useToast(),{data:I,isLoading:j,isFetching:A}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:e,manufacturerId:t.ManufacturerId,categoryCode:d??""},{skip:!t.ManufacturerId||!d}),O=async ie=>{try{b(ie),await o({routeResellerId:e,randmarSku:ie,shopifyHostName:n}).unwrap()&&E({title:"Success",description:"Product synced to Shopify successfully",variant:"success"})}catch(ae){console.error("Error syncing to Shopify:",ae),E({title:"Error",description:"Error syncing product to Shopify.",variant:"destructive"})}finally{b(null)}},q=async()=>{try{S(!0),C(!1),await l({routeResellerId:e,manufacturerId:t.ManufacturerId??"",categoryCode:d,shopifyHostName:n}).unwrap()&&E({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(ie){console.error("Error syncing to Shopify:",ie),E({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{S(!1)}},z=()=>{var ie,ae;return((ae=(ie=t.Categories)==null?void 0:ie.find(oe=>oe.CategoryCode===d))==null?void 0:ae.CategoryName)||d};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ManufacturerCategories,{categories:t.Categories||[],activeCategory:d,onSelectCategory:f}),n&&((V=t.Categories)==null?void 0:V.findIndex(ie=>ie.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:R,onOpenChange:C,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 mb-4",disabled:_,children:_?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(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 "',z(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:q,disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4 mb-4",children:j||A?Array.from({length:4}).map((ie,ae)=>jsxRuntime.jsx(ProductCard,{},ae)):I!=null&&I.Products&&(I==null?void 0:I.Products.length)>0?(te=I==null?void 0:I.Products)==null?void 0:te.map(ie=>jsxRuntime.jsx(ProductCard,{applicationId:e,item:ie,viewProductLink:`/${e}/Product/${ie.RandmarSKU}`,syncToShopify:!!n,isSyncToShopifyActionLoading:g===ie.RandmarSKU,syncToShopifyAction:()=>ie.RandmarSKU&&O(ie.RandmarSKU)},ie.RandmarSKU)):jsxRuntime.jsxs(Alert,{variant:"warning",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."})]})})]})}function PartnerRelationshipPage({applicationId:e,partnerId:t,userEmail:n,shopifyHostName:o,isSuperAdmin:l}){var j,A,O;const{data:d,isLoading:f}=useGetV4PartnerByApplicationIdPartnerAndPartnerIdQuery({applicationId:e,partnerId:t,withSpecification:!0}),{toast:g}=useToast(),[b]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[_,S]=React.useState(!1),[R,C]=React.useState(!1),E=async()=>{try{S(!0),C(!1),await b({routeResellerId:e??"",manufacturerId:t??"",shopifyHostName:o}).unwrap()&&g({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(q){console.error("Error syncing to Shopify:",q),g({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{S(!1)}},I=()=>d!=null&&d.Reseller?"reseller-overview":d!=null&&d.Manufacturer?"manufacturer-overview":"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 md:grid-cols-2",children:[jsxRuntime.jsx(PartnerCard,{account:d,loading:f,withAbout:!0,withVoice:!1,action:" "}),jsxRuntime.jsxs("div",{className:"grid gap-4",children:[((d==null?void 0:d.Manufacturer)||f)&&jsxRuntime.jsx(ManufacturerCard,{manufacturer:d==null?void 0:d.Manufacturer,loading:f,mainAction:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(ManufacturerGetStartedButton,{applicationId:e,manufacturer:d==null?void 0:d.Manufacturer}),o&&((A=(j=d==null?void 0:d.Manufacturer)==null?void 0:j.Categories)==null?void 0:A.findIndex(q=>q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:R,onOpenChange:C,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 ml-2",disabled:_,children:_?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 "',(O=d==null?void 0:d.Manufacturer)==null?void 0:O.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:E,disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(ResellerCard,{reseller:d==null?void 0:d.Reseller,loading:f})]})]}),((d==null?void 0:d.Reseller)||(d==null?void 0:d.Manufacturer))&&!f&&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:[(d==null?void 0:d.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"}),(d==null?void 0:d.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"}),(d==null?void 0:d.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"})]}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsContent,{value:"reseller-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ResellerOverview,{readonly:!0,appID:d.ApplicationId||"",reseller:d==null?void 0:d.Reseller,userEmail:n,isSuperAdmin:l,withoutReports:!0})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"manufacturer-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerOverviewPage,{readonly:!0,applicationId:d.ApplicationId||"",userEmail:n})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"products",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerProducts,{applicationId:e,manufacturer:d.Manufacturer,shopifyHostName:o})})})]})}),f&&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"})})]})}function ManufacturerBillingInfoSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState({}),b=React.useMemo(()=>({accountsPayableRep:(e==null?void 0:e.ContactName)??"",representativeEmail:(e==null?void 0:e.RepresentativeEmail)??"",phone:(e==null?void 0:e.Phone)??"",creditLimit:(e==null?void 0:e.CreditLimit)??0,terms:(e==null?void 0:e.Terms)??""}),[e]),{register:_,handleSubmit:S,reset:R,watch:C,formState:{errors:E,isSubmitting:I}}=useForm({defaultValues:b}),j=C(),A=React.useCallback(()=>t||!f?!1:JSON.stringify(j)!==JSON.stringify(f),[t,j,f]);React.useEffect(()=>{o&&o(A())},[A,o]),React.useEffect(()=>{e&&(R(b),g(b))},[e,R,b]);const O=async q=>{if(t)return;let z=!0,Q=!1;const F=[{key:"accountsPayableRep",apiKey:"ContactName",value:q.accountsPayableRep},{key:"representativeEmail",apiKey:"RepresentativeEmail",value:q.representativeEmail},{key:"phone",apiKey:"Phone",value:q.phone},{key:"terms",apiKey:"Terms",value:q.terms}];for(const V of F){const te=V.value,ie=e==null?void 0:e[V.apiKey];if(te!==ie&&te!==void 0){Q=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:V.apiKey,newValue:String(te)}).unwrap()||(z=!1,console.error(`Failed to update ${V.apiKey}`))}catch(ae){console.error(`Error updating ${V.apiKey}:`,ae),z=!1}}}z&&Q?(l({title:"Billing info",description:"Information updated successfully",variant:"success"}),g({...q}),o&&o(!1)):z?Q||l({title:"No changes",description:"No changes were made to the information.",variant:"info"}):l({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Billing, Credit, & Rebates"})}),jsxRuntime.jsx(CardContent,{children:n?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-48"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-36"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]}),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-16"}),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-16"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs("form",{onSubmit:S(O),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$2,{className:"text-sm font-medium leading-none",htmlFor:"accountsPayableRep",children:"Accounts Payable Representative"}),jsxRuntime.jsx(Input,{id:"accountsPayableRep",placeholder:"John Doe",..._("accountsPayableRep"),readOnly:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"representativeEmail",children:"Representative Email"}),jsxRuntime.jsx(Input,{id:"representativeEmail",placeholder:"john.doe@company.com",..._("representativeEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),readOnly:t}),E.representativeEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.representativeEmail.message})]})]}),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$2,{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone"}),jsxRuntime.jsx(Input,{id:"phone",placeholder:"(555) 123-4567",..._("phone"),readOnly:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"creditLimit",children:"Credit Limit"}),jsxRuntime.jsx("div",{className:"p-2 border rounded-md bg-gray-100",children:jsxRuntime.jsx(FormattedNumber,{value:(e==null?void 0:e.CreditLimit)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"terms",children:"Terms"}),jsxRuntime.jsx(Input,{id:"terms",placeholder:"NET 30 DAYS",..._("terms"),readOnly:!0})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I,className:"w-full sm:w-auto",children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function OpenToWorkSection({manufacturer:e,readonly:t=!1,isLoading:n}){const{toast:o}=useToast(),[l]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),d=React.useMemo(()=>({openToWork:(e==null?void 0:e.OpenToWork)??!1}),[e]),{reset:f,watch:g}=useForm({defaultValues:d});React.useEffect(()=>{e&&f(d)},[e,f,d]);const b=async _=>{if(!t)try{await l({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:"OpenToWork",newValue:_?"true":"false"}).unwrap()&&o({title:"Open to work info",description:"Information updated successfully",variant:"success"})}catch(S){console.error("Error updating",S)}};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Open to Work with Resellers"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})}):jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Resellers will be introducing their business, and communicating opportunities for your Brand through Randmar."}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"You'll engage directly with resellers, allow them to learn about your product lines, and grow your business faster."}),jsxRuntime.jsx("br",{}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Switch,{id:"openToWork",checked:g("openToWork"),onCheckedChange:_=>b(_),disabled:t}),jsxRuntime.jsx(Label$2,{htmlFor:"openToWork",children:"Open to work with Resellers"})]})]})})]})}const tagSuggestions=["Arts and Crafts","Cleaning Solutions","Clothing","Electronics","Generic Compatible Toner","Ink","Luggage and Bags","Miscellaneous","Networking Devices","Paper Products","Printers","Printing Supplies","Toner"];function ManufacturerPublicInfoSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState([]),[b,_]=React.useState({}),S=React.useMemo(()=>({publicName:(e==null?void 0:e.PublicName)??"",website:(e==null?void 0:e.Website)??"",customerServiceEmail:(e==null?void 0:e.PublicEmail)??"",publicResources:(e==null?void 0:e.PublicResourcesLink)??""}),[e]),{register:R,handleSubmit:C,reset:E,watch:I,formState:{errors:j,isSubmitting:A}}=useForm({defaultValues:S}),O=I(),q=React.useCallback(()=>t||!b?!1:JSON.stringify(O)!==JSON.stringify(b),[t,O,b]);React.useEffect(()=>{o&&o(q())},[q,o]),React.useEffect(()=>{e&&(E(S),g(e.Tags?e.Tags.split(",").map(V=>V.trim()):[]),_(S))},[e,E,S]);const z=async V=>{if(t)return;let te=!0,ie=!1;const ae=[{key:"publicName",apiKey:"PublicName",value:V.publicName},{key:"website",apiKey:"Website",value:V.website},{key:"manufacturerCategories",apiKey:"Tags",value:f.join(", ")},{key:"customerServiceEmail",apiKey:"PublicEmail",value:V.customerServiceEmail},{key:"publicResources",apiKey:"PublicResourcesLink",value:V.publicResources}];for(const oe of ae){const se=oe.value,ge=e==null?void 0:e[oe.apiKey],Ae=typeof ge=="boolean"?String(ge):ge;if(se!==Ae&&se!==void 0){ie=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:oe.apiKey,newValue:String(se)}).unwrap()||(te=!1)}catch(je){console.error(`Error updating ${oe.apiKey}:`,je),te=!1}}}te&&ie?(l({title:"Public info",description:"Information updated successfully",variant:"success"}),_({...V}),o&&o(!1)):te||l({title:"Update error",description:"Failed to update",variant:"destructive"})},Q=V=>!V||V.trim()==="",F=V=>{g(V)};return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Public Information"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),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:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-10"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-48"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),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.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(Q(I("publicName"))||Q(I("website"))||Q(I("customerServiceEmail")))&&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 Resellers."})]}),jsxRuntime.jsxs("form",{onSubmit:C(z),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"publicName",children:"Public Manufacturer Name *"}),jsxRuntime.jsx(Input,{id:"publicName",placeholder:"Company Name",...R("publicName",{}),className:Q(I("publicName"))?"input-error-indicator":"",readOnly:t}),j.publicName&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.publicName.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),jsxRuntime.jsx(Input,{id:"website",placeholder:"https://company.com",...R("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:Q(I("website"))?"input-error-indicator":"",readOnly:t}),j.website&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.website.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"manufacturerCategories",children:"Manufacturer Categories"}),jsxRuntime.jsx(MultiSelect,{options:tagSuggestions,selected:f,onChange:F,placeholder:"Select or type categories...",disabled:t})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"customerServiceEmail",children:"Customer Service Email *"}),jsxRuntime.jsx(Input,{id:"customerServiceEmail",placeholder:"support@company.com",...R("customerServiceEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:Q(I("customerServiceEmail"))?"input-error-indicator":"",readOnly:t}),j.customerServiceEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:j.customerServiceEmail.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"publicResources",children:"Public Resources"}),jsxRuntime.jsx(Input,{id:"publicResources",placeholder:"https://resources.company.com",...R("publicResources"),readOnly:t})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:A,className:"w-full sm:w-auto",children:A?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})]})})]})}function ManufacturerQualificationsSection({manufacturer:e,readonly:t=!1,isLoading:n,onUnsavedChanges:o}){const{toast:l}=useToast(),[d]=usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[f,g]=React.useState({}),b=React.useMemo(()=>({partnerPortal:(e==null?void 0:e.PartnerPortal)??"",partnerRegistrationLink:(e==null?void 0:e.PartnerRegistrationLink)??""}),[e]),{register:_,handleSubmit:S,reset:R,watch:C,formState:{errors:E,isSubmitting:I}}=useForm({defaultValues:b}),j=C(),A=React.useCallback(()=>t||!f?!1:JSON.stringify(j)!==JSON.stringify(f),[t,j,f]);React.useEffect(()=>{o&&o(A())},[A,o]),React.useEffect(()=>{e&&(R(b),g(b))},[e,R,b]);const O=async z=>{if(t)return!1;let Q=!0,F=!1;const V=[{key:"partnerPortal",apiKey:"PartnerPortal",value:z.partnerPortal},{key:"partnerRegistrationLink",apiKey:"PartnerRegistrationLink",value:z.partnerRegistrationLink}];for(const te of V){const ie=te.value,ae=e==null?void 0:e[te.apiKey];if(ie!==ae&&ie!==void 0){F=!0;try{await d({applicationId:(e==null?void 0:e.ManufacturerId)??"",fieldName:te.apiKey,newValue:String(ie)}).unwrap()||(Q=!1,console.error(`Failed to update ${te.apiKey}`))}catch(oe){console.error(`Error updating ${te.apiKey}:`,oe),Q=!1}}}Q&&F?(l({title:"Qualifications info",description:"Information updated successfully",variant:"success"}),g({...z}),o&&o(!1)):Q?F||l({title:"No changes",description:"No changes were made to the information.",variant:"info"}):l({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})},q=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?(\?[^\s#]*)??(#[^\s]*)?$/i;return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Qualifications"})}),jsxRuntime.jsx(CardContent,{children:n?jsxRuntime.jsxs("div",{className:"space-y-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-48"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})]}):jsxRuntime.jsxs("form",{onSubmit:S(O),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"partnerPortal",children:"Partner Portal"}),jsxRuntime.jsx(Input,{id:"partnerPortal",placeholder:"https://partner.example.com",..._("partnerPortal",{pattern:{value:q,message:"Invalid URL format"}}),readOnly:t}),E.partnerPortal&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.partnerPortal.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Label$2,{className:"text-sm font-medium leading-none",htmlFor:"partnerRegistrationLink",children:"Partner Registration Link"}),jsxRuntime.jsx(Input,{id:"partnerRegistrationLink",placeholder:"https://register.example.com",..._("partnerRegistrationLink",{pattern:{value:q,message:"Invalid URL format"}}),readOnly:t}),E.partnerRegistrationLink&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:E.partnerRegistrationLink.message})]}),!t&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I,className:"w-full sm:w-auto",children:I?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function ManufacturerReportsSection({manufacturerId:e,userEmail:t,isLoading:n}){const{toast:o}=useToast(),[l,{isLoading:d}]=usePostV4ManufacturerByRouteManufacturerIdDocumentAndDocumentNumberEmailMutation(),[f,g]=React.useState(null),[b,_]=React.useState(t),[S,R]=React.useState(!1),C=[{name:"Orders & Sales",reports:[{id:"OpenOrders",title:"Open Orders Report",description:"The Open Orders Report provides a snapshot of active orders, aiding your business in efficiently tracking and fulfilling customer demands.",icon:FileText},{id:"Sales",title:"Sales Report",description:"Summary of your company's sales activity over a certain period, detailing total sales and helping identifying trends, successes, and areas needing improvement.",icon:ChartNoAxesColumnIncreasing}]},{name:"Purchase Orders",reports:[{id:"PurchasedOrders",title:"Open Purchase Orders Report",description:"The Open Purchase Orders Report provides a snapshot of Randmar's active orders, aiding your business in efficiently tracking and fulfilling Randmar's inventory demands.",icon:ShoppingCart},{id:"Reorder",title:"Reordering Report",description:"The Reordering Report provides a snapshot of all part numbers auto-reordering statuses. Aiding your understanding of what will be automatically reordered by our system or not once the inventory reaches low numbers.",icon:ClipboardList}]},{name:"Inventory",reports:[{id:"Inventory",title:"Inventory Report",description:"Detailed document outlining the quantity, type, and value of products Randmar has on hand. It aids in managing stock levels, identifying shortages or surpluses, and informing purchasing decisions.",icon:Package},{id:"Products",title:"Products Report",description:"Detailed document outlining all your products properties. It provides a comprehensive overview of essential information and insights that help you make informed decisions.",icon:ClipboardList}]}],E=async j=>{g(j),R(!0)},I=async()=>{if(!(!f||!e))try{await l({routeManufacturerId:e,documentNumber:f.id,emailAddress:b}).unwrap(),o({title:"Report requested",description:`The ${f.title} will be sent to ${b} shortly.`,variant:"success"}),R(!1),_("")}catch(j){console.error("Error requesting report:",j),o({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}};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 Open Orders & Sales Report, to your Inventory Reports."})]}),jsxRuntime.jsx(CardContent,{className:"space-y-6",children:n?jsxRuntime.jsx(jsxRuntime.Fragment,{children:[1,2,3].map(j=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-48"}),[1,2].map(A=>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"})]},A))]},j))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:C.map(j=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:j.name}),j.reports.map(A=>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(A.icon,{className:"h-5 w-5 text-primary"})}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("h4",{className:"font-semibold text-sm",children:A.title}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:A.description})]}),jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>E(A),children:[jsxRuntime.jsx(Download,{className:"h-4 w-4"}),"Request"]})]},A.id))]},j.name))})}),jsxRuntime.jsx(Dialog,{open:S,onOpenChange:R,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsxs(DialogTitle,{children:["Request ",f==null?void 0:f.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:b,onChange:j=>_(j.target.value),placeholder:"your@email.com",className:"mt-2"})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>R(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{onClick:I,disabled:!b||d,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function ManufacturerResellerOrdersSection({manufacturerId:e}){const{data:t,isLoading:n,isError:o}=useGetV4ManufacturerByRouteManufacturerIdDocumentsActiveOrderDetailsQuery({routeManufacturerId:e}),d=(()=>{if(!t)return{all:{orders:0,amount:0},processing:{orders:0,amount:0},shipped:{orders:0,amount:0},delayed:{orders:0,amount:0}};const g=t.filter(z=>z.DocumentType==="Order"),b=t.filter(z=>z.DocumentType==="Shipment"),_=g.filter(z=>z.WarehouseCode!=="3PLE"),S=_.reduce((z,Q)=>z+(Q.Quantity||0),0),R=_.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),C=g.filter(z=>z.WarehouseCode==="3PLE"),E=C.reduce((z,Q)=>z+(Q.Quantity||0),0),I=C.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),j=b.length,A=b.reduce((z,Q)=>z+(Q.ExtendedPrice||0),0),O=S+E+j,q=R+I+A;return{all:{orders:O,amount:q},processing:{orders:S,amount:R},shipped:{orders:j,amount:A},delayed:{orders:E,amount:I}}})(),f=[{name:"All",icon:Package,color:"bg-blue-500",orders:d.all.orders,amount:d.all.amount},{name:"Processing",icon:RefreshCcw,color:"bg-yellow-500",orders:d.processing.orders,amount:d.processing.amount},{name:"Shipped",icon:Truck,color:"bg-green-500",orders:d.shipped.orders,amount:d.shipped.amount},{name:"Delayed",icon:CircleAlert,color:"bg-red-500",orders:d.delayed.orders,amount:d.delayed.amount}];return n?jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-40 mb-4"}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(g=>jsxRuntime.jsx(Skeleton,{className:"h-32 w-full"},g))})]})]}):o?jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"Failed to load reseller orders. Please try again later."})]})})]}):jsxRuntime.jsxs(Card,{className:"w-full md:col-span-2 xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reseller Orders"})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsxs("div",{className:"flex items-center mb-4",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Active Orders:"}),jsxRuntime.jsx("span",{className:"ml-2 font-bold",children:d.all.orders})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3.5",children:f.map(g=>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:`${g.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:g.name}),jsxRuntime.jsx("div",{className:`${g.color} bg-opacity-90 p-2 rounded-full`,children:jsxRuntime.jsx(g.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:g.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:g.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},g.name))})]})]})}function ManufacturerOverviewPage({applicationId:e,readonly:t,withReports:n,userEmail:o}){const{data:l,isLoading:d,isError:f}=useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:e,withSpecification:!0}),[g,b]=React.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),_=React.useCallback(()=>t?!1:g.publicInfo.hasUnsavedChanges||g.qualifications.hasUnsavedChanges||g.billingInfo.hasUnsavedChanges,[t,g]),S=React.useCallback((I,j)=>{b(A=>{var O;return((O=A[I])==null?void 0:O.hasUnsavedChanges)!==j.hasUnsavedChanges?(console.log(`Updating form state for ${I}:`,j.hasUnsavedChanges),{...A,[I]:j}):A})},[]),{NavigationGuardDialog:R}=useRouterNavigationGuard(_),[C,E]=React.useState(!0);return!d&&(l!=null&&l.SalesStatistics)&&l.SalesStatistics.length>0,jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[f?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:l==null?void 0:l.FiscalYearMonthStart,salesData:l==null?void 0:l.SalesData,isLoading:d}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChart,{salesData:(l==null?void 0:l.SalesStatistics)??[],isLoading:d}),jsxRuntime.jsx(ManufacturerResellerOrdersSection,{manufacturerId:e}),n&&jsxRuntime.jsx(ManufacturerPublicInfoSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:I=>S("publicInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(OpenToWorkSection,{manufacturer:l,readonly:t,isLoading:d}),n&&jsxRuntime.jsx(ManufacturerBillingInfoSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:I=>S("billingInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(ManufacturerQualificationsSection,{manufacturer:l,readonly:t,isLoading:d,onUnsavedChanges:I=>S("qualifications",{hasUnsavedChanges:I})})]}),n&&jsxRuntime.jsx(ManufacturerReportsSection,{manufacturerId:e,userEmail:o,isLoading:d})]}),jsxRuntime.jsx(R,{})]})}exports.ActiveOrdersCard=ActiveOrdersCard,exports.AiGeneratedContent=AiGeneratedContent,exports.Alert=Alert,exports.AlertDescription=AlertDescription,exports.AlertTitle=AlertTitle,exports.ApiKeyProvider=ApiKeyProvider,exports.AreaChart=AreaChart,exports.Avatar=Avatar,exports.AvatarFallback=AvatarFallback,exports.AvatarFooter=AvatarFooter,exports.AvatarImage=AvatarImage,exports.Badge=Badge,exports.Button=Button,exports.Card=Card,exports.CardContent=CardContent,exports.CardDescription=CardDescription,exports.CardFooter=CardFooter,exports.CardHeader=CardHeader,exports.CardTitle=CardTitle,exports.ChatLayout=ChatLayout,exports.ChatProvider=ChatProvider,exports.Checkbox=Checkbox,exports.Command=Command,exports.CommandDialog=CommandDialog,exports.CommandEmpty=CommandEmpty,exports.CommandGroup=CommandGroup,exports.CommandInput=CommandInput,exports.CommandItem=CommandItem,exports.CommandList=CommandList,exports.CommandSeparator=CommandSeparator,exports.CommandShortcut=CommandShortcut,exports.CountryFlag=CountryFlag,exports.DataTable=DataTable,exports.Dialog=Dialog,exports.DialogClose=DialogClose,exports.DialogContent=DialogContent,exports.DialogDescription=DialogDescription,exports.DialogFooter=DialogFooter,exports.DialogHeader=DialogHeader,exports.DialogOverlay=DialogOverlay,exports.DialogPortal=DialogPortal,exports.DialogTitle=DialogTitle,exports.DialogTrigger=DialogTrigger,exports.DropdownMenu=DropdownMenu,exports.DropdownMenuCheckboxItem=DropdownMenuCheckboxItem,exports.DropdownMenuContent=DropdownMenuContent,exports.DropdownMenuGroup=DropdownMenuGroup,exports.DropdownMenuItem=DropdownMenuItem,exports.DropdownMenuLabel=DropdownMenuLabel,exports.DropdownMenuPortal=DropdownMenuPortal,exports.DropdownMenuRadioGroup=DropdownMenuRadioGroup,exports.DropdownMenuRadioItem=DropdownMenuRadioItem,exports.DropdownMenuSeparator=DropdownMenuSeparator,exports.DropdownMenuShortcut=DropdownMenuShortcut,exports.DropdownMenuSub=DropdownMenuSub,exports.DropdownMenuSubContent=DropdownMenuSubContent,exports.DropdownMenuSubTrigger=DropdownMenuSubTrigger,exports.DropdownMenuTrigger=DropdownMenuTrigger,exports.ExploreManufacturers=ExploreManufacturers,exports.GeneralDocumentCard=GeneralDocumentCard,exports.Input=Input,exports.InputOTP=InputOTP,exports.InputOTPGroup=InputOTPGroup,exports.InputOTPSeparator=InputOTPSeparator,exports.InputOTPSlot=InputOTPSlot,exports.Label=Label$2,exports.Layout=Layout,exports.ManufacturerCard=ManufacturerCard,exports.ManufacturerGetStartedButton=ManufacturerGetStartedButton,exports.ManufacturerOverviewPage=ManufacturerOverviewPage,exports.ManufacturerReorderingCard=ManufacturerReorderingCard,exports.MultiSelect=MultiSelect,exports.Navbar=Navbar,exports.PartnerCard=PartnerCard,exports.PartnerRelationshipPage=PartnerRelationshipPage,exports.Popover=Popover,exports.PopoverAnchor=PopoverAnchor,exports.PopoverContent=PopoverContent,exports.PopoverTrigger=PopoverTrigger,exports.Preloader=Preloader,exports.ProductCard=ProductCard,exports.ProductImage=ProductImage,exports.ProductInventoryGrid=ProductInventoryGrid,exports.RadioGroup=RadioGroup$1,exports.RadioGroupItem=RadioGroupItem,exports.ResellerBillingOverviewCard=ResellerBillingOverviewCard,exports.ResellerCard=ResellerCard,exports.ResellerOverview=ResellerOverview,exports.ResellerQualificationsCard=ResellerQualificationsCard,exports.SalesOverviewCard=SalesOverviewCard,exports.ScrollArea=ScrollArea,exports.ScrollBar=ScrollBar,exports.Select=Select,exports.SelectContent=SelectContent,exports.SelectGroup=SelectGroup,exports.SelectItem=SelectItem,exports.SelectLabel=SelectLabel,exports.SelectScrollDownButton=SelectScrollDownButton,exports.SelectScrollUpButton=SelectScrollUpButton,exports.SelectTrigger=SelectTrigger,exports.SelectValue=SelectValue,exports.Separator=Separator$1,exports.Sheet=Sheet,exports.SheetClose=SheetClose,exports.SheetContent=SheetContent,exports.SheetDescription=SheetDescription,exports.SheetFooter=SheetFooter,exports.SheetHeader=SheetHeader,exports.SheetOverlay=SheetOverlay,exports.SheetPortal=SheetPortal,exports.SheetTitle=SheetTitle,exports.SheetTrigger=SheetTrigger,exports.Sidebar=Sidebar,exports.SidebarContent=SidebarContent,exports.SidebarFooter=SidebarFooter,exports.SidebarGroup=SidebarGroup,exports.SidebarGroupAction=SidebarGroupAction,exports.SidebarGroupContent=SidebarGroupContent,exports.SidebarGroupLabel=SidebarGroupLabel,exports.SidebarHeader=SidebarHeader,exports.SidebarInput=SidebarInput,exports.SidebarInset=SidebarInset,exports.SidebarMenu=SidebarMenu,exports.SidebarMenuAction=SidebarMenuAction,exports.SidebarMenuBadge=SidebarMenuBadge,exports.SidebarMenuButton=SidebarMenuButton,exports.SidebarMenuItem=SidebarMenuItem,exports.SidebarMenuSkeleton=SidebarMenuSkeleton,exports.SidebarMenuSub=SidebarMenuSub,exports.SidebarMenuSubButton=SidebarMenuSubButton,exports.SidebarMenuSubItem=SidebarMenuSubItem,exports.SidebarProvider=SidebarProvider,exports.SidebarRail=SidebarRail,exports.SidebarSeparator=SidebarSeparator,exports.SidebarTrigger=SidebarTrigger,exports.Skeleton=Skeleton,exports.Switch=Switch,exports.Table=Table,exports.TableBody=TableBody,exports.TableCaption=TableCaption,exports.TableCell=TableCell,exports.TableFooter=TableFooter,exports.TableHead=TableHead,exports.TableHeader=TableHeader,exports.TableRow=TableRow,exports.Tabs=Tabs,exports.TabsContent=TabsContent,exports.TabsList=TabsList,exports.TabsTrigger=TabsTrigger,exports.Textarea=Textarea,exports.Toast=Toast,exports.ToastAction=ToastAction,exports.ToastClose=ToastClose,exports.ToastDescription=ToastDescription,exports.ToastProvider=ToastProvider,exports.ToastTitle=ToastTitle,exports.ToastViewport=ToastViewport,exports.Toaster=Toaster,exports.Tooltip=Tooltip$1,exports.TooltipContent=TooltipContent,exports.TooltipProvider=TooltipProvider,exports.TooltipTrigger=TooltipTrigger,exports.Topbar=Topbar,exports.badgeVariants=badgeVariants,exports.buttonVariants=buttonVariants,exports.toast=toast,exports.useApiKey=useApiKey,exports.useChat=useChat,exports.useIsMobile=useIsMobile,exports.useSidebar=useSidebar,exports.useToast=useToast,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|