randmarcomps 1.337.0 → 1.340.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.
@@ -126,18 +126,21 @@ declare interface AssistantChatProps {
126
126
  }
127
127
 
128
128
  /**
129
- * A reusable component that displays an animated AI icon and thinking text
130
- * while fetching a text-based insight, then animates the response in.
131
- * It caches responses and prevents concurrent requests for the same prompt.
129
+ * A component that displays an animated AI icon and placeholder text while
130
+ * fetching an insight from the Gemini API. It leverages the useGemini hook
131
+ * to manage the entire data fetching and state management lifecycle.
132
132
  */
133
133
  export declare function AssistantInsight({ prompt, smartAndSlow, thinkingPlaceholderText, }: AssistantInsightProps): JSX.Element;
134
134
 
135
135
  /**
136
- * Props for the AssistantInsight component.
136
+ * Defines the props for the AssistantInsight component.
137
137
  */
138
138
  declare interface AssistantInsightProps {
139
+ /** The prompt to send to the AI for generating the insight. */
139
140
  prompt: string;
141
+ /** If true, uses a more powerful (and slower) model for the request. */
140
142
  smartAndSlow?: boolean;
143
+ /** Optional placeholder text to display while the AI is generating a response. */
141
144
  thinkingPlaceholderText?: string;
142
145
  }
143
146
 
@@ -92533,10 +92533,19 @@ function ProductOverviewPage({
92533
92533
  {
92534
92534
  value: "orders",
92535
92535
  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",
92536
- disabled: (((Q = S == null ? void 0 : S.ActiveOrderDetails) == null ? void 0 : Q.length) ?? 0) <= 0 && (((j = S == null ? void 0 : S.Returns) == null ? void 0 : j.length) ?? 0) <= 0,
92536
+ disabled: (((Q = S == null ? void 0 : S.ActiveOrderDetails) == null ? void 0 : Q.length) ?? 0) <= 0,
92537
92537
  children: "Orders"
92538
92538
  }
92539
92539
  ),
92540
+ /* @__PURE__ */ jsx(
92541
+ TabsTrigger,
92542
+ {
92543
+ value: "returns",
92544
+ 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",
92545
+ disabled: (((j = S == null ? void 0 : S.Returns) == null ? void 0 : j.length) ?? 0) <= 0,
92546
+ children: "Returns"
92547
+ }
92548
+ ),
92540
92549
  /* @__PURE__ */ jsx(
92541
92550
  TabsTrigger,
92542
92551
  {
@@ -92578,25 +92587,23 @@ function ProductOverviewPage({
92578
92587
  loading: b
92579
92588
  }
92580
92589
  ) }) }),
92581
- /* @__PURE__ */ jsxs(TabsContent, { value: "orders", children: [
92582
- (((oe = S == null ? void 0 : S.ActiveOrderDetails) == null ? void 0 : oe.length) ?? 0) > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
92583
- OrdersCard,
92584
- {
92585
- applicationId: t,
92586
- title: "Open Orders",
92587
- orders: S == null ? void 0 : S.ActiveOrderDetails,
92588
- loading: _
92589
- }
92590
- ) }),
92591
- (((ge = S == null ? void 0 : S.Returns) == null ? void 0 : ge.length) ?? 0) > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
92592
- ReturnsTable,
92593
- {
92594
- applicationId: t,
92595
- returns: S == null ? void 0 : S.Returns,
92596
- loading: _
92597
- }
92598
- ) })
92599
- ] }),
92590
+ /* @__PURE__ */ jsx(TabsContent, { value: "orders", children: (((oe = S == null ? void 0 : S.ActiveOrderDetails) == null ? void 0 : oe.length) ?? 0) > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
92591
+ OrdersCard,
92592
+ {
92593
+ applicationId: t,
92594
+ title: "Open Orders",
92595
+ orders: S == null ? void 0 : S.ActiveOrderDetails,
92596
+ loading: _
92597
+ }
92598
+ ) }) }),
92599
+ /* @__PURE__ */ jsx(TabsContent, { value: "returns", children: (((ge = S == null ? void 0 : S.Returns) == null ? void 0 : ge.length) ?? 0) > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
92600
+ ReturnsTable,
92601
+ {
92602
+ applicationId: t,
92603
+ returns: S == null ? void 0 : S.Returns,
92604
+ loading: _
92605
+ }
92606
+ ) }) }),
92600
92607
  /* @__PURE__ */ jsx(TabsContent, { value: "invoices", children: (((se = S == null ? void 0 : S.Invoices) == null ? void 0 : se.length) ?? 0) > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
92601
92608
  InvoicesTable,
92602
92609
  {
@@ -93691,87 +93698,104 @@ function ExternalProductCard({ product: t, viewProductLink: e }) {
93691
93698
  ] }) }) });
93692
93699
  }
93693
93700
  const resultCache = /* @__PURE__ */ new Map(), requestCache = /* @__PURE__ */ new Map();
93694
- function cleanHtmlString(t) {
93695
- let e = t.trim();
93696
- return e.startsWith("```html") && (e = e.substring(7).trim()), e.endsWith("```") && (e = e.slice(0, -3).trim()), e;
93701
+ function cleanResponseString(t, e) {
93702
+ const n = t.trim();
93703
+ if (e === "text")
93704
+ return n;
93705
+ const o = /^```(?:\w+\n)?([\s\S]+)\n```$/, l = n.match(o);
93706
+ return l ? l[1].trim() : n;
93697
93707
  }
93698
- const GetTextInsightFromAI = async (t, e, n, o = 3) => {
93699
- const l = `
93700
- Analyze the following prompt and provide a helpful, concise response formatted in simple HTML.
93708
+ const fetchGeminiResponse = async (t, e, n, o, l = 3) => {
93709
+ const f = `
93710
+ Analyze the following prompt and ${o === "html" ? `Provide a helpful, concise response formatted in simple HTML.
93701
93711
  - Use <p> tags for paragraphs.
93702
93712
  - Use <strong> for emphasis.
93703
93713
  - You can also use ordered (<ol>) and unordered (<ul>) lists with list items (<li>).
93704
- - Do not include <html>, <head>, <body>, or markdown \`\`\` fences. Output only the content itself.
93714
+ - Do not include <html>, <head>, <body>, or markdown \`\`\` fences. Output only the content itself.` : "Provide a helpful, concise response in plain text. Do not use any HTML tags or markdown formatting."}
93705
93715
  ---
93706
93716
  Prompt: "${e}"
93707
93717
  `;
93708
93718
  try {
93709
- const d = new GoogleGenAI({ apiKey: t }), f = n ? "gemini-2.5-pro" : "gemini-2.5-flash";
93710
- return (await d.chats.create({ model: f }).sendMessage({ message: l })).text ?? "<p>Sorry, I couldn't generate a response for this.</p>";
93711
- } catch (d) {
93712
- return console.error("Error fetching AI insight:", d), o > 0 ? (await new Promise((f) => setTimeout(f, (4 - o) * 500)), GetTextInsightFromAI(t, e, n, o - 1)) : "<p>An error occurred while generating the insight.</p>";
93713
- }
93719
+ const g = new GoogleGenAI({ apiKey: t }), b = n ? "gemini-1.5-pro-latest" : "gemini-1.5-flash-latest";
93720
+ return (await g.chats.create({ model: b }).sendMessage({ message: f })).text ?? "Sorry, I couldn't generate a response for this.";
93721
+ } catch (g) {
93722
+ return console.error("Error fetching AI response:", g), l > 0 ? (await new Promise((b) => setTimeout(b, (4 - l) * 500)), fetchGeminiResponse(t, e, n, o, l - 1)) : "An error occurred while generating the response.";
93723
+ }
93724
+ }, useGemini = (t = {}) => {
93725
+ const { useProModel: e = !1, outputFormat: n = "html" } = t, [o, l] = useState(null), [d, f] = useState(!1), [g, b] = useState(null), { apiKey: S } = useGeminiApiKey(), _ = useRef(null), C = useCallback(async (E) => {
93726
+ if (!S) {
93727
+ b("API Key is required.");
93728
+ return;
93729
+ }
93730
+ _.current = E;
93731
+ const R = `${E}::${n}`;
93732
+ if (resultCache.has(R)) {
93733
+ l(resultCache.get(R)), f(!1), b(null);
93734
+ return;
93735
+ }
93736
+ if (requestCache.has(R)) {
93737
+ f(!0);
93738
+ try {
93739
+ await requestCache.get(R), _.current === E && l(resultCache.get(R));
93740
+ } catch (M) {
93741
+ _.current === E && b(M instanceof Error ? M.message : "An unknown error occurred.");
93742
+ } finally {
93743
+ _.current === E && f(!1);
93744
+ }
93745
+ return;
93746
+ }
93747
+ f(!0), b(null);
93748
+ const A = fetchGeminiResponse(S, E, e, n).then((M) => {
93749
+ const I = cleanResponseString(M, n);
93750
+ return resultCache.set(R, I), I;
93751
+ }).catch((M) => {
93752
+ throw requestCache.delete(R), M;
93753
+ });
93754
+ requestCache.set(R, A);
93755
+ try {
93756
+ const M = await A;
93757
+ _.current === E && l(M);
93758
+ } catch (M) {
93759
+ _.current === E && b(M instanceof Error ? M.message : "An unknown error occurred.");
93760
+ } finally {
93761
+ requestCache.delete(R), _.current === E && f(!1);
93762
+ }
93763
+ }, [S, e, n]);
93764
+ return { response: o, isLoading: d, error: g, sendPrompt: C };
93714
93765
  };
93715
93766
  function AssistantInsight({
93716
93767
  prompt: t,
93717
93768
  smartAndSlow: e = !1,
93718
93769
  thinkingPlaceholderText: n = "Thinking..."
93719
93770
  }) {
93720
- const [o, l] = useState(""), [d, f] = useState(!0), [g, b] = useState(null), { apiKey: S } = useGeminiApiKey();
93771
+ const {
93772
+ response: o,
93773
+ isLoading: l,
93774
+ error: d,
93775
+ sendPrompt: f
93776
+ } = useGemini({
93777
+ useProModel: e,
93778
+ outputFormat: "html"
93779
+ });
93721
93780
  return useEffect(() => {
93722
- let _ = !1;
93723
- return (async () => {
93724
- if (!S || !t) {
93725
- if (_) return;
93726
- b("Prompt and API Key are required."), f(!1);
93727
- return;
93728
- }
93729
- if (resultCache.has(t)) {
93730
- if (_) return;
93731
- l(resultCache.get(t)), f(!1);
93732
- return;
93733
- }
93734
- if (requestCache.has(t)) {
93735
- if (_) return;
93736
- f(!0), await requestCache.get(t), !_ && resultCache.has(t) && l(resultCache.get(t)), _ || f(!1);
93737
- return;
93738
- }
93739
- try {
93740
- if (_) return;
93741
- f(!0);
93742
- const E = GetTextInsightFromAI(S, t, e).then((R) => {
93743
- const A = cleanHtmlString(R);
93744
- resultCache.set(t, A);
93745
- });
93746
- if (requestCache.set(t, E), await E, _) return;
93747
- resultCache.has(t) && l(resultCache.get(t));
93748
- } catch (E) {
93749
- if (_) return;
93750
- const R = E instanceof Error ? E.message : "An unknown error occurred.";
93751
- b(R), console.error(E);
93752
- } finally {
93753
- requestCache.delete(t), _ || f(!1);
93754
- }
93755
- })(), () => {
93756
- _ = !0;
93757
- };
93758
- }, [t, S, e]), /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-4 p-4 border rounded-lg bg-background", children: [
93781
+ t && f(t);
93782
+ }, [t, f]), /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-4 p-4 border rounded-lg bg-background", children: [
93759
93783
  /* @__PURE__ */ jsx(
93760
93784
  Bot,
93761
93785
  {
93762
- className: `mt-1 h-6 w-6 flex-shrink-0 ${d ? "animate-pulse text-primary" : "text-primary"}`
93786
+ className: `mt-1 h-6 w-6 flex-shrink-0 ${l ? "animate-pulse text-primary" : "text-primary"}`
93763
93787
  }
93764
93788
  ),
93765
93789
  /* @__PURE__ */ jsxs("div", { className: "w-full min-h-[4rem]", children: [
93766
- d && /* @__PURE__ */ jsxs(Fragment$1, { children: [
93790
+ l && /* @__PURE__ */ jsxs(Fragment$1, { children: [
93767
93791
  /* @__PURE__ */ jsx("p", { className: "font-medium text-muted-foreground", children: n }),
93768
93792
  /* @__PURE__ */ jsxs("div", { className: "space-y-2 mt-2", children: [
93769
93793
  /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-5/6" }),
93770
93794
  /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" })
93771
93795
  ] })
93772
93796
  ] }),
93773
- g && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600", children: g }),
93774
- !d && !g && o && // Render the cleaned HTML from the AI.
93797
+ d && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600", children: d }),
93798
+ !l && !d && o && // Renders the cleaned HTML response from the AI.
93775
93799
  /* @__PURE__ */ jsx(
93776
93800
  "div",
93777
93801
  {
@@ -1349,14 +1349,14 @@ img.ProseMirror-separator {
1349
1349
  .ProseMirror p {
1350
1350
  margin-bottom: 0.5em;
1351
1351
  }
1352
- `;function RichTextEditor({id:t,name:e,value:n,onChange:o,placeholder:l,className:d,...f}){const[g,b]=React.useState(!1),_=React.useRef(null),S=React.useRef(null),R=useEditor({extensions:[StarterKit,Underline],content:n,editorProps:{attributes:{class:"prose prose-sm sm:prose dark:prose-invert focus:outline-none",id:t??"",name:e??""}},onUpdate:({editor:j})=>{const q=j.getHTML();o({target:{id:t,name:e,value:q}})}});React.useEffect(()=>{R&&n!==R.getHTML()&&R.commands.setContent(n)},[n,R]);const C=React.useCallback(j=>{if(R)if(R.chain().focus(),j==="paragraph")R.chain().setParagraph().run();else{const q=Number.parseInt(j.slice(1));R.chain().setHeading({level:q}).run()}},[R]),E=React.useCallback(j=>{if(R)switch(R.chain().focus(),j){case"bold":R.chain().toggleBold().run();break;case"italic":R.chain().toggleItalic().run();break;case"underline":R.chain().toggleUnderline().run();break;case"strike":R.chain().toggleStrike().run();break;case"bulletList":R.chain().toggleBulletList().run();break;case"orderedList":R.chain().toggleOrderedList().run();break}},[R]),A=React.useCallback(()=>{b(j=>!j)},[]),M=React.useCallback(j=>{const q=j.target.value;R&&R.commands.setContent(q),o({target:{id:t,name:e,value:q}})},[o,R,t,e]),I=React.useCallback(()=>{!g&&R&&R.commands.focus()},[g,R]);return R?jsxRuntime.jsxs("div",{ref:S,className:cn("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",d),onClick:I,...f,children:[jsxRuntime.jsx("style",{children:editorStyles}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[jsxRuntime.jsxs(Select,{onValueChange:C,disabled:g,children:[jsxRuntime.jsx(SelectTrigger,{className:"w-[160px]",children:jsxRuntime.jsx(SelectValue,{placeholder:"Format"})}),jsxRuntime.jsx(SelectContent,{children:formatOptions.map(j=>jsxRuntime.jsx(SelectItem,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>jsxRuntime.jsxs(Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(j),className:R.isActive(j)?"bg-muted":"",disabled:g,children:[j==="bold"&&jsxRuntime.jsx(Bold$1,{className:"h-4 w-4"}),j==="italic"&&jsxRuntime.jsx(Italic$1,{className:"h-4 w-4"}),j==="underline"&&jsxRuntime.jsx(Underline$1,{className:"h-4 w-4"}),j==="strike"&&jsxRuntime.jsx(Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&jsxRuntime.jsx(List$1,{className:"h-4 w-4"}),j==="orderedList"&&jsxRuntime.jsx(ListOrdered,{className:"h-4 w-4"})]},j)),jsxRuntime.jsx(Button,{type:"button",variant:"ghost",size:"sm",onClick:A,className:g?"bg-muted":"",children:jsxRuntime.jsx(Code$1,{className:"h-4 w-4"})})]}),jsxRuntime.jsx("div",{className:"p-3",children:g?jsxRuntime.jsx(Textarea,{ref:_,id:t,name:e,value:R.getHTML(),onChange:M,className:cn("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",d),placeholder:l}):jsxRuntime.jsx(EditorContent,{editor:R})})]}):null}function ReceiptsTable({receipts:t=null,loading:e=!1}){const n=React.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:d})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:d.original.Location??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:d})=>formatYYYYMMDDIntToDateString(d.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:d})=>d.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!0}],[]),o=React.useMemo(()=>{const d={};if(t){const f=Array.from(new Set(t.map(b=>b.Location).filter(b=>b!=null)));d.Location=f;const g=Array.from(new Set(t.map(b=>formatYYYYMMDDIntToDateString(b.ReceiptDate)).filter(b=>b!=="N/A"&&b!=="Invalid Date"))).sort((b,_)=>new Date(_).getTime()-new Date(b).getTime());d.ReceiptDate=g}return d},[t]),l=t||[];return jsxRuntime.jsx(DataTable,{columns:n,data:l,uniqueValues:o,loading:e,tableClass:"bg-card text-card-foreground"})}const formatDate$1=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},getStatusVariant=t=>{const e=(t==null?void 0:t.toLowerCase())||"";return e.includes("accepted")?"success":e.includes("error")||e.includes("rejected")?"destructive":"neutral"};function ReturnsTable({applicationId:t,returns:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:f})=>{const g=f.original.ReturnNumber1||f.original.ReturnNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Return/${g}`,className:"font-medium text-primary hover:underline",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for return ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:f})=>formatDate$1(f.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:f})=>{const g=f.original.InvoiceNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${g}`,className:"text-blue-600 hover:underline dark:text-blue-400",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:f})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:f.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:f})=>{const g=f.original.Status,b=getStatusVariant(g);let _="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return b==="success"?_="border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400":b==="destructive"&&(_="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400"),g?jsxRuntime.jsx(Badge,{variant:"outline",className:`${_} font-medium`,children:g}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:f})=>f.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:f})=>formatDate$1(f.original.LastUpdatedDate)!=="N/A"?formatDate$1(f.original.LastUpdatedDate):"—",enableSorting:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(S=>S.Status).filter(Boolean)));f.Status=g;const b=Array.from(new Set(e.map(S=>S.ReasonForReturn).filter(Boolean)));f.ReasonForReturn=b;const _=Array.from(new Set(e.map(S=>S.WarehouseLocation).filter(Boolean)));f.WarehouseLocation=_}return f},[e]),d=React.useMemo(()=>e?[...e].sort((g,b)=>(b.ReturnNumber1||b.ReturnNumber||"").localeCompare(g.ReturnNumber1||g.ReturnNumber||"")):[],[e]);return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Returns"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l})})]})}function InvoicesTable({applicationId:t,invoices:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"InvoiceNumber",header:"Number",cell:({row:f})=>f.original.InvoiceNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${f.original.InvoiceNumber}`,className:"font-medium text-primary hover:underline",children:f.original.InvoiceNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",f.original.InvoiceNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"InvoiceDate",header:"Date",cell:({row:f})=>formatYYYYMMDDIntToDateString(f.original.InvoiceDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"OrderNumber",header:"Order Number",cell:({row:f})=>f.original.OrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/GeneralDocument/${f.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:f.original.OrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for order ",f.original.OrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PONumber",header:"PO Number",cell:({row:f})=>f.original.PONumber&&f.original.PONumber.trim().length>0?f.original.PONumber:"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ShipToName",header:"Ship To Name",cell:({row:f})=>f.original.ShipToName??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:f})=>f.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:f})=>formatMoney(f.original.UnitPrice??0),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:f})=>f.original.Location??"—",enableSorting:!0,enableFiltering:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(C=>C.ShipToName).filter(C=>C!=null)));f.ShipToName=g;const b=Array.from(new Set(e.map(C=>C.InvoiceNumber).filter(C=>C!=null)));f.InvoiceNumber=b;const _=Array.from(new Set(e.map(C=>C.OrderNumber).filter(C=>C!=null)));f.OrderNumber=_;const S=Array.from(new Set(e.map(C=>C.PONumber).filter(C=>C!=null)));f.PONumber=S;const R=Array.from(new Set(e.map(C=>C.Location).filter(C=>C!=null)));f.Location=R}return f},[e]),d=e||[];return jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l,loading:n,tableClass:"bg-card text-card-foreground"})}function ProductOverviewPage({applicationId:t,sku:e,productDefaultOpportunityNumber:n="",productOnAddToCart:o,productAddingToCart:l=!1,productShopifyHostname:d,productCustomAction:f=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var I,j,q,z,Q,V,F,te,ne,se,ge,oe;const{data:g,isLoading:b}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e,withSpecification:!1},{skip:!t||!e}),{data:_,isLoading:S}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e,withSpecification:!0},{skip:!g}),[R,C]=React.useState("stats"),[E,A]=React.useState(!1);React.useEffect(()=>{var Ne,Oe,Fe,ze,$e,Be,qe,Ge;if(S||!_){A(!1);return}const Ae={stats:(((Ne=_==null?void 0:_.SalesStatistics)==null?void 0:Ne.length)??0)<=0,inventory:(((Fe=(Oe=_==null?void 0:_.Distribution)==null?void 0:Oe.Inventory)==null?void 0:Fe.length)??0)<=0,opportunities:(((ze=_==null?void 0:_.Opportunities)==null?void 0:ze.length)??0)<=0,orders:((($e=_==null?void 0:_.ActiveOrderDetails)==null?void 0:$e.length)??0)<=0&&(((Be=_==null?void 0:_.Returns)==null?void 0:Be.length)??0)<=0,invoices:(((qe=_==null?void 0:_.CompletedOrderDetails)==null?void 0:qe.length)??0)<=0,warehouse:(((Ge=_==null?void 0:_.Receipts)==null?void 0:Ge.length)??0)<=0},je=Object.values(Ae).some(He=>!He);if(A(je),je&&Ae[R]){const He=Object.keys(Ae).find(Ze=>!Ae[Ze]);He&&C(He)}},[S,_,R]);const M=(g==null?void 0:g.ManufacturerId)!==t;return console.log("readonly",M),jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3",children:[jsxRuntime.jsx("div",{className:"@md:col-span-2",children:jsxRuntime.jsx(ProductCard,{applicationId:t,product:_||g,defaultOpportunityNumber:n,onAddToCart:o,addingToCart:l,shopifyHostname:d,customAction:f})}),jsxRuntime.jsxs(Card,{className:"flex flex-col",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{children:[jsxRuntime.jsx(Info,{className:"h-5 w-5 inline mr-2"})," Additionnal information"]})}),jsxRuntime.jsx(CardContent,{className:"basis-0 mb-6 grow overflow-y-auto",children:b?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-1 w-full my-6"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-1"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Category Name"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.ProductType)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Master Carton"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.MasterCarton)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Skid Quantity"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.SkidQuantity)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Automatic Reorder"}),jsxRuntime.jsx("span",{className:"font-medium",children:g!=null&&g.AutoUpdate?"Yes":"No"})]}),((g==null?void 0:g.VoiceoverCaption)||(g==null?void 0:g.BodyHTML))&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("hr",{className:"my-6"}),jsxRuntime.jsx("div",{className:"text-muted-foreground mb-2",children:"Description"}),(g==null?void 0:g.VoiceoverCaption)&&jsxRuntime.jsx("div",{children:g==null?void 0:g.VoiceoverCaption}),(g==null?void 0:g.BodyHTML)&&jsxRuntime.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:(g==null?void 0:g.BodyHTML)??""}})]})]})})]})]}),jsxRuntime.jsx("div",{className:"my-4",children:b||S?jsxRuntime.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})}):E&&jsxRuntime.jsxs(Tabs,{value:R,onValueChange:C,children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[jsxRuntime.jsx(TabsTrigger,{value:"stats",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((I=_==null?void 0:_.SalesStatistics)==null?void 0:I.length)??0)<=0,children:"Statistics"}),jsxRuntime.jsx(TabsTrigger,{value:"inventory",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((q=(j=_==null?void 0:_.Distribution)==null?void 0:j.Inventory)==null?void 0:q.length)??0)<=0,children:"Inventory"}),jsxRuntime.jsx(TabsTrigger,{value:"opportunities",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((z=_==null?void 0:_.Opportunities)==null?void 0:z.length)??0)<=0,children:"Opportunities"}),jsxRuntime.jsx(TabsTrigger,{value:"orders",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((Q=_==null?void 0:_.ActiveOrderDetails)==null?void 0:Q.length)??0)<=0&&(((V=_==null?void 0:_.Returns)==null?void 0:V.length)??0)<=0,children:"Orders"}),jsxRuntime.jsx(TabsTrigger,{value:"invoices",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((F=_==null?void 0:_.Invoices)==null?void 0:F.length)??0)<=0,children:"Invoices"}),jsxRuntime.jsx(TabsTrigger,{value:"warehouse",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((te=_==null?void 0:_.Receipts)==null?void 0:te.length)??0)<=0,children:"Latest Warehouse Receiving"})]}),jsxRuntime.jsx(TabsContent,{value:"stats",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(SalesChartCard,{statistics:(_==null?void 0:_.SalesStatistics)??[],loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"inventory",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ProductInventoryGrid,{inventory:((ne=_==null?void 0:_.Distribution)==null?void 0:ne.Inventory)??[],className:"bg-card text-card-foreground"})})}),jsxRuntime.jsx(TabsContent,{value:"opportunities",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OpportunitiesTable,{applicationId:t,opportunities:g==null?void 0:g.Opportunities,loading:b})})}),jsxRuntime.jsxs(TabsContent,{value:"orders",children:[(((se=_==null?void 0:_.ActiveOrderDetails)==null?void 0:se.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Open Orders",orders:_==null?void 0:_.ActiveOrderDetails,loading:S})}),(((ge=_==null?void 0:_.Returns)==null?void 0:ge.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReturnsTable,{applicationId:t,returns:_==null?void 0:_.Returns,loading:S})})]}),jsxRuntime.jsx(TabsContent,{value:"invoices",children:(((oe=_==null?void 0:_.Invoices)==null?void 0:oe.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(InvoicesTable,{applicationId:t,invoices:_==null?void 0:_.Invoices,loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"warehouse",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReceiptsTable,{receipts:_==null?void 0:_.Receipts,loading:S})})})]})})]})}function AssistantChat(t){return jsxRuntime.jsx(Card,{className:"max-w-6xl",children:jsxRuntime.jsx(ChatLayout,{className:"h-[40em]",userId:t.userId,userName:t.userName,assistantOnly:!0,initialPrompt:t.initialPrompt})})}function getEndDateStatus(t){if(!t)return{text:"No End Date",variant:"neutral",daysRemaining:null};const e=new Date(t);if(isNaN(e.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const n=new Date,o=new Date(e.getFullYear(),e.getMonth(),e.getDate()),l=new Date(n.getFullYear(),n.getMonth(),n.getDate()),d=o.getTime()-l.getTime(),f=Math.ceil(d/(1e3*60*60*24));return f<0?{text:`Ended ${Math.abs(f)}d ago`,variant:"destructive",daysRemaining:f}:f===0?{text:"Ends today",variant:"destructive",daysRemaining:f}:f<=7?{text:`Ends in ${f}d`,variant:"destructive",daysRemaining:f}:f<=30?{text:`Ends in ${f}d`,variant:"warning",daysRemaining:f}:{text:`Ends in ${f}d`,variant:"neutral",daysRemaining:f}}const formatDate=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function OpportunitiesTable({applicationId:t,opportunities:e=null,loading:n=!1}){var te;const{toast:o}=useToast(),[l,d]=React.useState({}),[f,g]=React.useState(!1),[b,_]=React.useState(""),[S,R]=React.useState(null),{data:C}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t},{skip:!t}),E=React.useCallback((ne,se,ge)=>{d(oe=>({...oe,[ne]:{...oe[ne],[se]:ge}}))},[]),[A]=usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),M=React.useCallback(async ne=>{if(!(C!=null&&C.IsReseller))return;if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const se=ne.BidNumber;E(se,"isSettingDefault",!0),A({routeResellerId:t,manufacturerId:ne.ManufacturerId??"",opportunityNumber:se}).unwrap().then(()=>{o({title:"Success",description:`Opportunity "${ne.OpportunityName||ne.Opportunity||se}" was successfully set as default.`,variant:"success"})}).catch(ge=>{var oe;console.error("Set as default error:",ge),o({title:"Error",description:((oe=ge.data)==null?void 0:oe.message)||ge.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{E(se,"isSettingDefault",!1)})},[t,A,o,E,C==null?void 0:C.IsReseller]),[I]=usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=React.useCallback(ne=>{if(C!=null&&C.IsReseller){if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}R(ne),_(""),g(!0)}},[o,C==null?void 0:C.IsReseller]),q=React.useCallback(async()=>{if(!(C!=null&&C.IsReseller))return;if(!S||!S.BidNumber){o({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!b.trim()||!/\S+@\S+\.\S+/.test(b)){o({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const ne=S.BidNumber;E(ne,"isSendingReport",!0),I({routeResellerId:t,manufacturerId:S.ManufacturerId??"",bidNumber:ne,emailAddress:b}).unwrap().then(()=>{o({title:"Success",description:`A report for "${S.OpportunityName||S.Opportunity||ne}" was successfully sent to ${b}.`,variant:"success"}),g(!1)}).catch(se=>{var ge;console.error("Send report by email error:",se),o({title:"Error",description:((ge=se.data)==null?void 0:ge.message)||se.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{E(ne,"isSendingReport",!1),f||(R(null),_(""))})},[S,b,t,I,o,E,g]),z=React.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:ne})=>jsxRuntime.jsx("div",{className:"w-20 h-8",children:jsxRuntime.jsx(PartnerLogo,{id:ne.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:ne=>ne.OpportunityName||ne.Opportunity,header:"Opportunity",cell:({getValue:ne})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:ne()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:ne})=>ne.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:ne})=>{const se=ne.original,ge=se.Active===!0,oe=getEndDateStatus(se.EndDate);let Ae="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return oe.variant==="destructive"?Ae="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400":oe.variant==="warning"&&(Ae="border-yellow-500 bg-yellow-100 text-yellow-700 dark:border-yellow-600 dark:bg-yellow-900/50 dark:text-yellow-400"),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[jsxRuntime.jsx(Badge,{variant:"outline",className:ge?"border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400 font-medium":"border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400 font-medium",children:ge?"Active":"Inactive"}),se.EndDate&&jsxRuntime.jsx(Badge,{variant:"outline",className:`${Ae} font-medium`,children:oe.text}),jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:jsxRuntime.jsx(Info,{className:"h-4 w-4 text-muted-foreground"})})}),jsxRuntime.jsx(TooltipContent,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:jsxRuntime.jsxs("div",{className:"text-sm space-y-1",children:[jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Start:"})," ",formatDate(se.StartDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"End:"})," ",formatDate(se.EndDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Updated:"})," ",formatDate(se.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:ne})=>{var Oe,Fe;const se=ne.original;if(!se.BidNumber)return jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const ge=se.BidNumber,oe=(Oe=l[ge])==null?void 0:Oe.isSettingDefault,Ae=(S==null?void 0:S.BidNumber)===ge&&((Fe=l[ge])==null?void 0:Fe.isSendingReport),je=oe||Ae,Ne=se.CanBeSetAsDefault===!0;return jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Opportunity/${se.ManufacturerId}/${se.BidNumber}`,children:jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",className:"flex items-center",children:[jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," View"]})}),(C==null?void 0:C.IsReseller)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",onClick:()=>M(se),disabled:je||!Ne,title:Ne?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[oe?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",onClick:()=>j(se),disabled:je,title:"Send report by email",className:"flex items-center",children:[Ae?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[l,M,j,S,C==null?void 0:C.IsReseller,t]),Q=React.useMemo(()=>{const ne={};if(e){const se=Array.from(new Set(e.map(oe=>oe.ManufacturerId).filter(oe=>oe!=null)));ne.ManufacturerId=se;const ge=Array.from(new Set(e.map(oe=>oe.OpportunityName||oe.Opportunity).filter(oe=>oe!=null)));ne.opportunityDisplay=ge}return ne},[e]),V=e||[],F=S!=null&&S.BidNumber?(te=l[S.BidNumber])==null?void 0:te.isSendingReport:!1;return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})," "]}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:z,data:V,uniqueValues:Q})})]}),jsxRuntime.jsx(Dialog,{open:f,onOpenChange:ne=>{g(ne),ne||(R(null),_(""))},children:jsxRuntime.jsxs(DialogContent,{className:"@sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Send Opportunity Report"}),jsxRuntime.jsxs(DialogDescription,{children:["Enter the email address to send the report for opportunity: ",jsxRuntime.jsx("br",{}),jsxRuntime.jsx("span",{className:"font-semibold",children:(S==null?void 0:S.OpportunityName)||(S==null?void 0:S.Opportunity)||"N/A"}),(S==null?void 0:S.BidNumber)&&jsxRuntime.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",S.BidNumber]})]})]}),jsxRuntime.jsx("div",{className:"grid gap-4 py-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",className:"text-right",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",type:"email",value:b,onChange:ne=>_(ne.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:F})]})}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>g(!1),disabled:F,children:"Cancel"}),jsxRuntime.jsxs(Button,{type:"submit",onClick:q,disabled:F,children:[F&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function useLoadScript(t){const[e,n]=React.useState(!0),[o,l]=React.useState(null),[d,f]=React.useState(!1),g=()=>{n(!1),f(!0)};return React.useEffect(()=>{if(!document){const R=new Error(`[ScriptLoadingError] document not defined when attempting to load ${t}`);l(R);return}const b=document.querySelector(`script[src="${t}"]`);if(b!=null&&b.dataset.loaded){g();return}const _=b||document.createElement("script");b||(_.src=t);const S=()=>{_.dataset.loaded="1",g()};_.addEventListener("load",S),_.addEventListener("error",R=>{console.error("Failed to load script:",t,R);const C=new Error(`[ScriptLoadingError] Failed to load script: ${t}`);l(C)}),b||document.head.append(_)},[]),{isLoading:e,error:o,isSuccess:d}}const isGoogleReady=t=>t&&t.charts,isGoogleChartsReady=(t,e)=>{const{controls:n,toolbarItems:o,getChartEditor:l}=t;return e&&e.charts&&e.visualization&&e.visualization.ChartWrapper&&e.visualization.Dashboard&&(!n||e.visualization.ChartWrapper)&&(!l||e.visualization.ChartEditor)&&(!o||e.visualization.drawToolbar)},getGoogleInstanceFromWindow=t=>window.google;function useLoadGoogleCharts(t){const{chartVersion:e="current",chartPackages:n=["corechart","controls"],chartLanguage:o="en",mapsApiKey:l}=t,[d,f]=React.useState(null),[g,b]=React.useState(null),[_,S]=React.useState(null),{isLoading:R,error:C,isSuccess:E}=useLoadScript(t.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return React.useEffect(()=>{if(!E)return;const A=getGoogleInstanceFromWindow();if(!isGoogleReady(A)){const M=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");b(M);return}if(isGoogleChartsReady(t,A)){f(A);return}A.charts.load(e,{packages:n,language:o,mapsApiKey:l}),A.charts.setOnLoadCallback(()=>{if(!isGoogleChartsReady(t,A)){const M=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(M),S(M);return}f(A)})},[E]),{error:C||g||_,isLoading:R,google:d}}const chartDefaultProps={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},GoogleChartControls=t=>{const{isReady:e,chartControls:n,filter:o}=t;return!e||!n||!(n!=null&&n.length)?null:React.createElement(React.Fragment,null,n.filter(l=>{let{controlProp:d,control:f}=l;return o?o({control:f,controlProp:d}):!0}).map(l=>{let{control:d}=l;return React.createElement("div",{key:d.getContainerId(),id:d.getContainerId()})}))};let uniqueID=0;const generateUniqueID=()=>(uniqueID+=1,`reactgooglegraph-${uniqueID}`),Mr=class Mr{};Qt(Mr,"initializeControls",e=>{for(let n=0;n<e.length;n+=1){const{controlType:o,options:l,controlWrapperParams:d}=e[n].controlProp;d&&"state"in d&&e[n].control.setState(d.state),e[n].control.setOptions(l),e[n].control.setControlType(o)}}),Qt(Mr,"listenToControlEvents",(e,n)=>{const{google:o}=n;return e.flatMap(l=>{const{control:d,controlProp:f}=l,{controlEvents:g=[]}=f;return g.map(b=>{const{callback:_,eventName:S}=b;return o.visualization.events.addListener(d,S,function(){for(var R=arguments.length,C=new Array(R),E=0;E<R;E++)C[E]=arguments[E];_({chartWrapper:null,controlWrapper:d,props:n,google:o,eventArgs:C})})})})}),Qt(Mr,"createControlId",e=>{let n;return typeof e>"u"?n=`googlechart-control-${generateUniqueID()}`:n=e,n}),Qt(Mr,"createChartControls",e=>{const{controls:n,google:o}=e;return n?n.map((l,d)=>{const{controlID:f,controlType:g,options:b,controlWrapperParams:_}=l,S=Mr.createControlId(f);return{controlProp:l,control:new o.visualization.ControlWrapper({containerId:S,controlType:g,options:b,..._})}}):null}),Qt(Mr,"addControls",e=>{const{chartWrapper:n,chartDashboard:o}=e,l=Mr.createChartControls(e);return!l||!o||!n?null:(o.bind(l.map(d=>{let{control:f}=d;return f}),n),Mr.initializeControls(l),l)});let GoogleChartControlsInternal=Mr;const useCreateChartControls=t=>{const[e,n]=React__namespace.useState(null);return[React__namespace.useMemo(()=>!e||!t?null:t.map((l,d)=>{const f=e[d];return f?{controlProp:l,control:f}:void 0}).flatMap(l=>l?[l]:[]),[e,t]),n]},useListenToControlEvents=(t,e)=>{React__namespace.useEffect(()=>{const n=GoogleChartControlsInternal.listenToControlEvents(t??[],e);return()=>{n.forEach(o=>{e.google.visualization.events.removeListener(o)})}},[t,e])},useChartControls=t=>{const[e,n]=useCreateChartControls(t.controls);return useListenToControlEvents(e??[],t),{addControls:l=>{const d=GoogleChartControlsInternal.addControls(l);n((d==null?void 0:d.map(f=>f.control))??null)},renderControl:l=>{const{chartWrapper:d,chartDashboard:f}=t;return React__namespace.createElement(GoogleChartControls,{...t,isReady:!!(d&&f),chartControls:e,filter:l})}}},useChartId=t=>{const e=React__namespace.useRef(null);return{chartId:(()=>{const{graphID:l,graph_id:d}=t,f=l||d;let g;return f?g=f:g=e.current||generateUniqueID(),e.current=g,e.current})()}},DEFAULT_CHART_COLORS=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],loadDataTableFromSpreadSheet=async function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((o,l)=>{const d=`${n.headers?`headers=${n.headers}`:"headers=0"}`,f=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,g=`${n.gid?`&gid=${n.gid}`:""}`,b=`${n.sheet?`&sheet=${n.sheet}`:""}`,_=`${n.access_token?`&access_token=${n.access_token}`:""}`,S=`${d}${g}${b}${f}${_}`,R=`${e}/gviz/tq?${S}`;new t.visualization.Query(R).send(E=>{E.isError()?l(`Error in query: ${E.getMessage()} ${E.getDetailedMessage()}`):o(E.getDataTable())})})},GRAY_COLOR="#CCCCCC",wr=class wr{};Qt(wr,"grayOutHiddenColumnsLabel",(e,n)=>{const{googleChartWrapper:o,options:l}=e;if(!o){console.error("googleChartWrapper is not defined");return}const d=o.getDataTable();if(!d)return;const f=d.getNumberOfColumns();if(n.length>0===!1)return;const b=Array.from({length:f-1}).map((_,S)=>{const R=wr.getColumnId(d,S+1);return n.includes(R)?GRAY_COLOR:l&&l.colors?l.colors[S]:DEFAULT_CHART_COLORS[S]});o.setOptions({...l,colors:b}),o.draw()}),Qt(wr,"listenToLegendToggle",(e,n)=>{const[o,l]=n,{google:d,googleChartWrapper:f}=e;if(!f){console.error("googleChartWrapper is not defined");return}return d.visualization.events.addListener(f,"select",()=>{const b=f.getChart().getSelection(),_=f.getDataTable();if(b.length===0||b[0].row!==null||!_)return;const S=b[0].column,R=wr.getColumnId(_,S);o!=null&&o.includes(R)?l(C=>[...C.filter(E=>E!==R)]):l(C=>[...C,R])})}),Qt(wr,"draw",async e=>{const{data:n,diffdata:o,rows:l,columns:d,options:f,chartType:g,formatters:b,spreadSheetUrl:_,spreadSheetQueryParameters:S,googleChartDashboard:R,googleChartWrapper:C,google:E,hiddenColumns:A,legendToggle:M,legend_toggle:I}=e;if(!C){console.error("draw was called with googleChartWrapper = null");return}let j,q=null;if(o){const te=E.visualization.arrayToDataTable(o.old),ne=E.visualization.arrayToDataTable(o.new);q=E.visualization[g].prototype.computeDiff(te,ne)}n?n instanceof E.visualization.DataTable?j=n:Array.isArray(n)?j=E.visualization.arrayToDataTable(n):j=new E.visualization.DataTable(n):l&&d?j=E.visualization.arrayToDataTable([d,...l]):_?j=await loadDataTableFromSpreadSheet(E,_,S):j=E.visualization.arrayToDataTable([]);const z=j.getNumberOfColumns(),Q=Array(z).fill(0).map((te,ne)=>{const se=wr.getColumnId(j,ne);return A.includes(se)?{label:j.getColumnLabel(ne),type:j.getColumnType(ne),calc:()=>null}:ne}),V=C.getChart();C.getChartType()==="Timeline"&&V&&V.clearChart(),C.setChartType(g),C.setOptions(f||{});const F=new E.visualization.DataView(j);F.setColumns(Q),C.setDataTable(F),C.draw(),R&&R.draw(j),q&&(C.setDataTable(q),C.draw()),b&&(wr.applyFormatters({dataTable:j,formatters:b,google:E}),C.setDataTable(j),C.draw()),(M===!0||I===!0)&&wr.grayOutHiddenColumnsLabel(e,A)}),Qt(wr,"getColumnId",(e,n)=>e.getColumnId(n)||e.getColumnLabel(n)),Qt(wr,"applyFormatters",e=>{let{dataTable:n,formatters:o,google:l}=e;for(let d of o)switch(d.type){case"ArrowFormat":{new l.visualization.ArrowFormat(d.options).format(n,d.column);return}case"BarFormat":{new l.visualization.BarFormat(d.options).format(n,d.column);return}case"ColorFormat":{const f=new l.visualization.ColorFormat(d.options),{ranges:g}=d;if(g)for(let b of g)f.addRange(...b);f.format(n,d.column);return}case"DateFormat":{new l.visualization.DateFormat(d.options).format(n,d.column);return}case"NumberFormat":{new l.visualization.NumberFormat(d.options).format(n,d.column);return}case"PatternFormat":{new l.visualization.PatternFormat(d.options).format(n,d.column);return}default:{console.warn(`Unknown formatter type: ${d.type}`);return}}});let GoogleChartInternal=wr;const useGoogleChartDataTable=t=>{const{google:e,googleChartWrapper:n,googleChartDashboard:o}=t,[l,d]=React__namespace.useState([]);React__namespace.useEffect(()=>{n&&GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:n,googleChartDashboard:o,google:e})},[l,t.data,t.rows,t.columns,t.options,t.chartLoaderScriptUrl,t.chartType,t.formatters,t.spreadSheetUrl,t.spreadSheetQueryParameters,t.legendToggle,t.legend_toggle]);const f=()=>{const{googleChartWrapper:_}=t;_&&_.draw()},g=_=>{const S=[],{legendToggle:R,legend_toggle:C}=t;if(GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:_,googleChartDashboard:o,google:e}),window.addEventListener("resize",f),C||R){const E=GoogleChartInternal.listenToLegendToggle(t,[l,d]);E&&S.push(E)}return S},b=(_,S)=>{window.removeEventListener("resize",f),S.forEach(R=>{e.visualization.events.removeListener(R)}),_.getChartType()==="Timeline"&&_.getChart()&&_.getChart().clearChart()};React__namespace.useEffect(()=>{if(!n)return;const _=g(n);return()=>{b(n,_)}},[n,g,b])},listenToEvents=t=>{const{chartEvents:e,google:n,googleChartWrapper:o}=t;if(e){if(!o){console.warn("listenToEvents was called before chart wrapper ready.");return}return e.map(l=>{let{eventName:d,callback:f}=l;return n.visualization.events.addListener(o,d,function(){for(var g=arguments.length,b=new Array(g),_=0;_<g;_++)b[_]=arguments[_];f({chartWrapper:o,props:t,google:n,eventArgs:b})})})}},useGoogleChartEvents=t=>{React.useEffect(()=>{if(!t.googleChartWrapper)return;const e=listenToEvents(t);return()=>{e==null||e.forEach(n=>{t.google.visualization.events.removeListener(n)})}},[t])},GoogleChart=t=>{const[e,n]=React__namespace.useState(null),[o,l]=React__namespace.useState(null),{addControls:d,renderControl:f}=useChartControls({...t,chartDashboard:o,chartWrapper:e});useGoogleChartEvents({...t,googleChartWrapper:e});const{chartId:g}=useChartId(t),b=React__namespace.useRef(null),_=React__namespace.useRef(null);React__namespace.useEffect(()=>{const{options:j,google:q,chartType:z,chartWrapperParams:Q,toolbarItems:V,getChartEditor:F,getChartWrapper:te,onLoad:ne}=t,se={chartType:z,options:j,containerId:g,...Q},ge=new q.visualization.ChartWrapper(se);ge.setOptions(j||{}),te==null||te(ge,q);const oe=new q.visualization.Dashboard(b.current);V&&q.visualization.drawToolbar(_.current,V);let Ae=null;F&&(Ae=new q.visualization.ChartEditor,F({chartEditor:Ae,chartWrapper:ge,google:q})),d({...t,chartDashboard:oe,chartWrapper:ge}),n(ge),l(oe),ne==null||ne(q,{google:q,chartWrapper:ge,chartEditor:Ae,chartDashboard:oe})},[]),useGoogleChartDataTable({...t,googleChartWrapper:e,googleChartDashboard:o});const S=()=>{const{width:j,height:q,options:z,style:Q,className:V,rootProps:F,google:te}=t,ne={height:q||z&&z.height,width:j||z&&z.width,...Q};return React__namespace.createElement("div",{id:g,style:ne,className:V,...F})},R=()=>t.toolbarItems?React__namespace.createElement("div",{ref:_}):null,{width:C,height:E,options:A,style:M}=t,I={height:E||A&&A.height,width:C||A&&A.width,...M};return t.render?React__namespace.createElement("div",{ref:b,style:I},React__namespace.createElement("div",{ref:_,id:"toolbar"}),t.render({renderChart:S,renderControl:f,renderToolbar:R})):React__namespace.createElement("div",{ref:b,style:I},f(j=>{let{controlProp:q}=j;return q.controlPosition!=="bottom"}),S(),f(j=>{let{controlProp:q}=j;return q.controlPosition==="bottom"}),R())},ChartContext=React__namespace.createContext(chartDefaultProps),ContextProvider=t=>{let{children:e,value:n}=t;return React__namespace.createElement(ChartContext.Provider,{value:n},e)},ChartView=t=>{const{google:e,isLoading:n,error:o}=useLoadGoogleCharts(t);return n?t.loader??null:o?t.errorElement??null:e?React.createElement(GoogleChart,{google:e,...t}):null},Chart=t=>{const e={...chartDefaultProps,...t};return React.createElement(ContextProvider,{value:e},React.createElement(ChartView,e))};var GoogleDataTableColumnRoleType;(function(t){t.annotation="annotation",t.annotationText="annotationText",t.certainty="certainty",t.emphasis="emphasis",t.interval="interval",t.scope="scope",t.style="style",t.tooltip="tooltip",t.domain="domain"})(GoogleDataTableColumnRoleType||(GoogleDataTableColumnRoleType={}));function parseHsl(t){const e=t.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return e?{h:parseFloat(e[1]),s:parseFloat(e[2]),l:parseFloat(e[3])}:null}function hslToHex(t,e,n){n/=100;const o=e*Math.min(n,1-n)/100,l=d=>{const f=(d+t/30)%12,g=n-o*Math.max(Math.min(f-3,9-f,1),-1);return Math.round(255*g).toString(16).padStart(2,"0")};return`#${l(0)}${l(8)}${l(4)}`}const Treemap=React__namespace.forwardRef(({data:t,options:e,height:n="500px",className:o,loading:l,disableClick:d=!0,...f},g)=>{const b=React__namespace.useRef(null),[_,S]=React__namespace.useState(null);React__namespace.useEffect(()=>{if(!b.current)return;const E=b.current,A=()=>{const q=getComputedStyle(E).getPropertyValue("--primary").trim();if(q){const z=parseHsl(q);if(z){const{h:Q,s:V,l:F}=z;S({minColor:hslToHex(Q,V,Math.min(100,F+50)),midColor:hslToHex(Q,V,Math.min(100,F+35)),maxColor:hslToHex(Q,V,Math.min(100,F+20))})}return!0}return!1};if(A())return;let M=0;const I=20,j=setInterval(()=>{(A()||M>=I)&&clearInterval(j),M++},100);return()=>{j&&clearInterval(j)}},[]);const R=React__namespace.useMemo(()=>{const E={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"hsl(var(--background))",generateTooltip:(A,M)=>{var q;const I=(q=t[A+1])==null?void 0:q[0];if(!I)return"";const j=formatMoney(M);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
1352
+ `;function RichTextEditor({id:t,name:e,value:n,onChange:o,placeholder:l,className:d,...f}){const[g,b]=React.useState(!1),_=React.useRef(null),S=React.useRef(null),R=useEditor({extensions:[StarterKit,Underline],content:n,editorProps:{attributes:{class:"prose prose-sm sm:prose dark:prose-invert focus:outline-none",id:t??"",name:e??""}},onUpdate:({editor:j})=>{const q=j.getHTML();o({target:{id:t,name:e,value:q}})}});React.useEffect(()=>{R&&n!==R.getHTML()&&R.commands.setContent(n)},[n,R]);const C=React.useCallback(j=>{if(R)if(R.chain().focus(),j==="paragraph")R.chain().setParagraph().run();else{const q=Number.parseInt(j.slice(1));R.chain().setHeading({level:q}).run()}},[R]),E=React.useCallback(j=>{if(R)switch(R.chain().focus(),j){case"bold":R.chain().toggleBold().run();break;case"italic":R.chain().toggleItalic().run();break;case"underline":R.chain().toggleUnderline().run();break;case"strike":R.chain().toggleStrike().run();break;case"bulletList":R.chain().toggleBulletList().run();break;case"orderedList":R.chain().toggleOrderedList().run();break}},[R]),A=React.useCallback(()=>{b(j=>!j)},[]),M=React.useCallback(j=>{const q=j.target.value;R&&R.commands.setContent(q),o({target:{id:t,name:e,value:q}})},[o,R,t,e]),I=React.useCallback(()=>{!g&&R&&R.commands.focus()},[g,R]);return R?jsxRuntime.jsxs("div",{ref:S,className:cn("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",d),onClick:I,...f,children:[jsxRuntime.jsx("style",{children:editorStyles}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[jsxRuntime.jsxs(Select,{onValueChange:C,disabled:g,children:[jsxRuntime.jsx(SelectTrigger,{className:"w-[160px]",children:jsxRuntime.jsx(SelectValue,{placeholder:"Format"})}),jsxRuntime.jsx(SelectContent,{children:formatOptions.map(j=>jsxRuntime.jsx(SelectItem,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>jsxRuntime.jsxs(Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(j),className:R.isActive(j)?"bg-muted":"",disabled:g,children:[j==="bold"&&jsxRuntime.jsx(Bold$1,{className:"h-4 w-4"}),j==="italic"&&jsxRuntime.jsx(Italic$1,{className:"h-4 w-4"}),j==="underline"&&jsxRuntime.jsx(Underline$1,{className:"h-4 w-4"}),j==="strike"&&jsxRuntime.jsx(Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&jsxRuntime.jsx(List$1,{className:"h-4 w-4"}),j==="orderedList"&&jsxRuntime.jsx(ListOrdered,{className:"h-4 w-4"})]},j)),jsxRuntime.jsx(Button,{type:"button",variant:"ghost",size:"sm",onClick:A,className:g?"bg-muted":"",children:jsxRuntime.jsx(Code$1,{className:"h-4 w-4"})})]}),jsxRuntime.jsx("div",{className:"p-3",children:g?jsxRuntime.jsx(Textarea,{ref:_,id:t,name:e,value:R.getHTML(),onChange:M,className:cn("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",d),placeholder:l}):jsxRuntime.jsx(EditorContent,{editor:R})})]}):null}function ReceiptsTable({receipts:t=null,loading:e=!1}){const n=React.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:d})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:d.original.Location??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:d})=>formatYYYYMMDDIntToDateString(d.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:d})=>d.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!0}],[]),o=React.useMemo(()=>{const d={};if(t){const f=Array.from(new Set(t.map(b=>b.Location).filter(b=>b!=null)));d.Location=f;const g=Array.from(new Set(t.map(b=>formatYYYYMMDDIntToDateString(b.ReceiptDate)).filter(b=>b!=="N/A"&&b!=="Invalid Date"))).sort((b,_)=>new Date(_).getTime()-new Date(b).getTime());d.ReceiptDate=g}return d},[t]),l=t||[];return jsxRuntime.jsx(DataTable,{columns:n,data:l,uniqueValues:o,loading:e,tableClass:"bg-card text-card-foreground"})}const formatDate$1=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},getStatusVariant=t=>{const e=(t==null?void 0:t.toLowerCase())||"";return e.includes("accepted")?"success":e.includes("error")||e.includes("rejected")?"destructive":"neutral"};function ReturnsTable({applicationId:t,returns:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:f})=>{const g=f.original.ReturnNumber1||f.original.ReturnNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Return/${g}`,className:"font-medium text-primary hover:underline",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for return ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:f})=>formatDate$1(f.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:f})=>{const g=f.original.InvoiceNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${g}`,className:"text-blue-600 hover:underline dark:text-blue-400",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:f})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:f.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:f})=>{const g=f.original.Status,b=getStatusVariant(g);let _="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return b==="success"?_="border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400":b==="destructive"&&(_="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400"),g?jsxRuntime.jsx(Badge,{variant:"outline",className:`${_} font-medium`,children:g}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:f})=>f.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:f})=>formatDate$1(f.original.LastUpdatedDate)!=="N/A"?formatDate$1(f.original.LastUpdatedDate):"—",enableSorting:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(S=>S.Status).filter(Boolean)));f.Status=g;const b=Array.from(new Set(e.map(S=>S.ReasonForReturn).filter(Boolean)));f.ReasonForReturn=b;const _=Array.from(new Set(e.map(S=>S.WarehouseLocation).filter(Boolean)));f.WarehouseLocation=_}return f},[e]),d=React.useMemo(()=>e?[...e].sort((g,b)=>(b.ReturnNumber1||b.ReturnNumber||"").localeCompare(g.ReturnNumber1||g.ReturnNumber||"")):[],[e]);return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Returns"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l})})]})}function InvoicesTable({applicationId:t,invoices:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"InvoiceNumber",header:"Number",cell:({row:f})=>f.original.InvoiceNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${f.original.InvoiceNumber}`,className:"font-medium text-primary hover:underline",children:f.original.InvoiceNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",f.original.InvoiceNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"InvoiceDate",header:"Date",cell:({row:f})=>formatYYYYMMDDIntToDateString(f.original.InvoiceDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"OrderNumber",header:"Order Number",cell:({row:f})=>f.original.OrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/GeneralDocument/${f.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:f.original.OrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for order ",f.original.OrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PONumber",header:"PO Number",cell:({row:f})=>f.original.PONumber&&f.original.PONumber.trim().length>0?f.original.PONumber:"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ShipToName",header:"Ship To Name",cell:({row:f})=>f.original.ShipToName??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:f})=>f.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:f})=>formatMoney(f.original.UnitPrice??0),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:f})=>f.original.Location??"—",enableSorting:!0,enableFiltering:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(C=>C.ShipToName).filter(C=>C!=null)));f.ShipToName=g;const b=Array.from(new Set(e.map(C=>C.InvoiceNumber).filter(C=>C!=null)));f.InvoiceNumber=b;const _=Array.from(new Set(e.map(C=>C.OrderNumber).filter(C=>C!=null)));f.OrderNumber=_;const S=Array.from(new Set(e.map(C=>C.PONumber).filter(C=>C!=null)));f.PONumber=S;const R=Array.from(new Set(e.map(C=>C.Location).filter(C=>C!=null)));f.Location=R}return f},[e]),d=e||[];return jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l,loading:n,tableClass:"bg-card text-card-foreground"})}function ProductOverviewPage({applicationId:t,sku:e,productDefaultOpportunityNumber:n="",productOnAddToCart:o,productAddingToCart:l=!1,productShopifyHostname:d,productCustomAction:f=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var I,j,q,z,Q,V,F,te,ne,se,ge,oe;const{data:g,isLoading:b}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e,withSpecification:!1},{skip:!t||!e}),{data:_,isLoading:S}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e,withSpecification:!0},{skip:!g}),[R,C]=React.useState("stats"),[E,A]=React.useState(!1);React.useEffect(()=>{var Ne,Oe,Fe,ze,$e,Be,qe,Ge;if(S||!_){A(!1);return}const Ae={stats:(((Ne=_==null?void 0:_.SalesStatistics)==null?void 0:Ne.length)??0)<=0,inventory:(((Fe=(Oe=_==null?void 0:_.Distribution)==null?void 0:Oe.Inventory)==null?void 0:Fe.length)??0)<=0,opportunities:(((ze=_==null?void 0:_.Opportunities)==null?void 0:ze.length)??0)<=0,orders:((($e=_==null?void 0:_.ActiveOrderDetails)==null?void 0:$e.length)??0)<=0&&(((Be=_==null?void 0:_.Returns)==null?void 0:Be.length)??0)<=0,invoices:(((qe=_==null?void 0:_.CompletedOrderDetails)==null?void 0:qe.length)??0)<=0,warehouse:(((Ge=_==null?void 0:_.Receipts)==null?void 0:Ge.length)??0)<=0},je=Object.values(Ae).some(He=>!He);if(A(je),je&&Ae[R]){const He=Object.keys(Ae).find(Ze=>!Ae[Ze]);He&&C(He)}},[S,_,R]);const M=(g==null?void 0:g.ManufacturerId)!==t;return console.log("readonly",M),jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3",children:[jsxRuntime.jsx("div",{className:"@md:col-span-2",children:jsxRuntime.jsx(ProductCard,{applicationId:t,product:_||g,defaultOpportunityNumber:n,onAddToCart:o,addingToCart:l,shopifyHostname:d,customAction:f})}),jsxRuntime.jsxs(Card,{className:"flex flex-col",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{children:[jsxRuntime.jsx(Info,{className:"h-5 w-5 inline mr-2"})," Additionnal information"]})}),jsxRuntime.jsx(CardContent,{className:"basis-0 mb-6 grow overflow-y-auto",children:b?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-1 w-full my-6"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-1"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Category Name"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.ProductType)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Master Carton"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.MasterCarton)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Skid Quantity"}),jsxRuntime.jsx("span",{className:"font-medium",children:(g==null?void 0:g.SkidQuantity)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Automatic Reorder"}),jsxRuntime.jsx("span",{className:"font-medium",children:g!=null&&g.AutoUpdate?"Yes":"No"})]}),((g==null?void 0:g.VoiceoverCaption)||(g==null?void 0:g.BodyHTML))&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("hr",{className:"my-6"}),jsxRuntime.jsx("div",{className:"text-muted-foreground mb-2",children:"Description"}),(g==null?void 0:g.VoiceoverCaption)&&jsxRuntime.jsx("div",{children:g==null?void 0:g.VoiceoverCaption}),(g==null?void 0:g.BodyHTML)&&jsxRuntime.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:(g==null?void 0:g.BodyHTML)??""}})]})]})})]})]}),jsxRuntime.jsx("div",{className:"my-4",children:b||S?jsxRuntime.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})}):E&&jsxRuntime.jsxs(Tabs,{value:R,onValueChange:C,children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[jsxRuntime.jsx(TabsTrigger,{value:"stats",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((I=_==null?void 0:_.SalesStatistics)==null?void 0:I.length)??0)<=0,children:"Statistics"}),jsxRuntime.jsx(TabsTrigger,{value:"inventory",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((q=(j=_==null?void 0:_.Distribution)==null?void 0:j.Inventory)==null?void 0:q.length)??0)<=0,children:"Inventory"}),jsxRuntime.jsx(TabsTrigger,{value:"opportunities",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((z=_==null?void 0:_.Opportunities)==null?void 0:z.length)??0)<=0,children:"Opportunities"}),jsxRuntime.jsx(TabsTrigger,{value:"orders",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((Q=_==null?void 0:_.ActiveOrderDetails)==null?void 0:Q.length)??0)<=0,children:"Orders"}),jsxRuntime.jsx(TabsTrigger,{value:"returns",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((V=_==null?void 0:_.Returns)==null?void 0:V.length)??0)<=0,children:"Returns"}),jsxRuntime.jsx(TabsTrigger,{value:"invoices",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((F=_==null?void 0:_.Invoices)==null?void 0:F.length)??0)<=0,children:"Invoices"}),jsxRuntime.jsx(TabsTrigger,{value:"warehouse",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",disabled:(((te=_==null?void 0:_.Receipts)==null?void 0:te.length)??0)<=0,children:"Latest Warehouse Receiving"})]}),jsxRuntime.jsx(TabsContent,{value:"stats",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(SalesChartCard,{statistics:(_==null?void 0:_.SalesStatistics)??[],loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"inventory",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ProductInventoryGrid,{inventory:((ne=_==null?void 0:_.Distribution)==null?void 0:ne.Inventory)??[],className:"bg-card text-card-foreground"})})}),jsxRuntime.jsx(TabsContent,{value:"opportunities",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OpportunitiesTable,{applicationId:t,opportunities:g==null?void 0:g.Opportunities,loading:b})})}),jsxRuntime.jsx(TabsContent,{value:"orders",children:(((se=_==null?void 0:_.ActiveOrderDetails)==null?void 0:se.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Open Orders",orders:_==null?void 0:_.ActiveOrderDetails,loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"returns",children:(((ge=_==null?void 0:_.Returns)==null?void 0:ge.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReturnsTable,{applicationId:t,returns:_==null?void 0:_.Returns,loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"invoices",children:(((oe=_==null?void 0:_.Invoices)==null?void 0:oe.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(InvoicesTable,{applicationId:t,invoices:_==null?void 0:_.Invoices,loading:S})})}),jsxRuntime.jsx(TabsContent,{value:"warehouse",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReceiptsTable,{receipts:_==null?void 0:_.Receipts,loading:S})})})]})})]})}function AssistantChat(t){return jsxRuntime.jsx(Card,{className:"max-w-6xl",children:jsxRuntime.jsx(ChatLayout,{className:"h-[40em]",userId:t.userId,userName:t.userName,assistantOnly:!0,initialPrompt:t.initialPrompt})})}function getEndDateStatus(t){if(!t)return{text:"No End Date",variant:"neutral",daysRemaining:null};const e=new Date(t);if(isNaN(e.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const n=new Date,o=new Date(e.getFullYear(),e.getMonth(),e.getDate()),l=new Date(n.getFullYear(),n.getMonth(),n.getDate()),d=o.getTime()-l.getTime(),f=Math.ceil(d/(1e3*60*60*24));return f<0?{text:`Ended ${Math.abs(f)}d ago`,variant:"destructive",daysRemaining:f}:f===0?{text:"Ends today",variant:"destructive",daysRemaining:f}:f<=7?{text:`Ends in ${f}d`,variant:"destructive",daysRemaining:f}:f<=30?{text:`Ends in ${f}d`,variant:"warning",daysRemaining:f}:{text:`Ends in ${f}d`,variant:"neutral",daysRemaining:f}}const formatDate=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function OpportunitiesTable({applicationId:t,opportunities:e=null,loading:n=!1}){var te;const{toast:o}=useToast(),[l,d]=React.useState({}),[f,g]=React.useState(!1),[b,_]=React.useState(""),[S,R]=React.useState(null),{data:C}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t},{skip:!t}),E=React.useCallback((ne,se,ge)=>{d(oe=>({...oe,[ne]:{...oe[ne],[se]:ge}}))},[]),[A]=usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),M=React.useCallback(async ne=>{if(!(C!=null&&C.IsReseller))return;if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const se=ne.BidNumber;E(se,"isSettingDefault",!0),A({routeResellerId:t,manufacturerId:ne.ManufacturerId??"",opportunityNumber:se}).unwrap().then(()=>{o({title:"Success",description:`Opportunity "${ne.OpportunityName||ne.Opportunity||se}" was successfully set as default.`,variant:"success"})}).catch(ge=>{var oe;console.error("Set as default error:",ge),o({title:"Error",description:((oe=ge.data)==null?void 0:oe.message)||ge.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{E(se,"isSettingDefault",!1)})},[t,A,o,E,C==null?void 0:C.IsReseller]),[I]=usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=React.useCallback(ne=>{if(C!=null&&C.IsReseller){if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}R(ne),_(""),g(!0)}},[o,C==null?void 0:C.IsReseller]),q=React.useCallback(async()=>{if(!(C!=null&&C.IsReseller))return;if(!S||!S.BidNumber){o({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!b.trim()||!/\S+@\S+\.\S+/.test(b)){o({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const ne=S.BidNumber;E(ne,"isSendingReport",!0),I({routeResellerId:t,manufacturerId:S.ManufacturerId??"",bidNumber:ne,emailAddress:b}).unwrap().then(()=>{o({title:"Success",description:`A report for "${S.OpportunityName||S.Opportunity||ne}" was successfully sent to ${b}.`,variant:"success"}),g(!1)}).catch(se=>{var ge;console.error("Send report by email error:",se),o({title:"Error",description:((ge=se.data)==null?void 0:ge.message)||se.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{E(ne,"isSendingReport",!1),f||(R(null),_(""))})},[S,b,t,I,o,E,g]),z=React.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:ne})=>jsxRuntime.jsx("div",{className:"w-20 h-8",children:jsxRuntime.jsx(PartnerLogo,{id:ne.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:ne=>ne.OpportunityName||ne.Opportunity,header:"Opportunity",cell:({getValue:ne})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:ne()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:ne})=>ne.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:ne})=>{const se=ne.original,ge=se.Active===!0,oe=getEndDateStatus(se.EndDate);let Ae="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return oe.variant==="destructive"?Ae="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400":oe.variant==="warning"&&(Ae="border-yellow-500 bg-yellow-100 text-yellow-700 dark:border-yellow-600 dark:bg-yellow-900/50 dark:text-yellow-400"),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[jsxRuntime.jsx(Badge,{variant:"outline",className:ge?"border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400 font-medium":"border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400 font-medium",children:ge?"Active":"Inactive"}),se.EndDate&&jsxRuntime.jsx(Badge,{variant:"outline",className:`${Ae} font-medium`,children:oe.text}),jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:jsxRuntime.jsx(Info,{className:"h-4 w-4 text-muted-foreground"})})}),jsxRuntime.jsx(TooltipContent,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:jsxRuntime.jsxs("div",{className:"text-sm space-y-1",children:[jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Start:"})," ",formatDate(se.StartDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"End:"})," ",formatDate(se.EndDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Updated:"})," ",formatDate(se.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:ne})=>{var Oe,Fe;const se=ne.original;if(!se.BidNumber)return jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const ge=se.BidNumber,oe=(Oe=l[ge])==null?void 0:Oe.isSettingDefault,Ae=(S==null?void 0:S.BidNumber)===ge&&((Fe=l[ge])==null?void 0:Fe.isSendingReport),je=oe||Ae,Ne=se.CanBeSetAsDefault===!0;return jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Opportunity/${se.ManufacturerId}/${se.BidNumber}`,children:jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",className:"flex items-center",children:[jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," View"]})}),(C==null?void 0:C.IsReseller)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",onClick:()=>M(se),disabled:je||!Ne,title:Ne?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[oe?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",onClick:()=>j(se),disabled:je,title:"Send report by email",className:"flex items-center",children:[Ae?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[l,M,j,S,C==null?void 0:C.IsReseller,t]),Q=React.useMemo(()=>{const ne={};if(e){const se=Array.from(new Set(e.map(oe=>oe.ManufacturerId).filter(oe=>oe!=null)));ne.ManufacturerId=se;const ge=Array.from(new Set(e.map(oe=>oe.OpportunityName||oe.Opportunity).filter(oe=>oe!=null)));ne.opportunityDisplay=ge}return ne},[e]),V=e||[],F=S!=null&&S.BidNumber?(te=l[S.BidNumber])==null?void 0:te.isSendingReport:!1;return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})," "]}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:z,data:V,uniqueValues:Q})})]}),jsxRuntime.jsx(Dialog,{open:f,onOpenChange:ne=>{g(ne),ne||(R(null),_(""))},children:jsxRuntime.jsxs(DialogContent,{className:"@sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Send Opportunity Report"}),jsxRuntime.jsxs(DialogDescription,{children:["Enter the email address to send the report for opportunity: ",jsxRuntime.jsx("br",{}),jsxRuntime.jsx("span",{className:"font-semibold",children:(S==null?void 0:S.OpportunityName)||(S==null?void 0:S.Opportunity)||"N/A"}),(S==null?void 0:S.BidNumber)&&jsxRuntime.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",S.BidNumber]})]})]}),jsxRuntime.jsx("div",{className:"grid gap-4 py-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",className:"text-right",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",type:"email",value:b,onChange:ne=>_(ne.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:F})]})}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>g(!1),disabled:F,children:"Cancel"}),jsxRuntime.jsxs(Button,{type:"submit",onClick:q,disabled:F,children:[F&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function useLoadScript(t){const[e,n]=React.useState(!0),[o,l]=React.useState(null),[d,f]=React.useState(!1),g=()=>{n(!1),f(!0)};return React.useEffect(()=>{if(!document){const R=new Error(`[ScriptLoadingError] document not defined when attempting to load ${t}`);l(R);return}const b=document.querySelector(`script[src="${t}"]`);if(b!=null&&b.dataset.loaded){g();return}const _=b||document.createElement("script");b||(_.src=t);const S=()=>{_.dataset.loaded="1",g()};_.addEventListener("load",S),_.addEventListener("error",R=>{console.error("Failed to load script:",t,R);const C=new Error(`[ScriptLoadingError] Failed to load script: ${t}`);l(C)}),b||document.head.append(_)},[]),{isLoading:e,error:o,isSuccess:d}}const isGoogleReady=t=>t&&t.charts,isGoogleChartsReady=(t,e)=>{const{controls:n,toolbarItems:o,getChartEditor:l}=t;return e&&e.charts&&e.visualization&&e.visualization.ChartWrapper&&e.visualization.Dashboard&&(!n||e.visualization.ChartWrapper)&&(!l||e.visualization.ChartEditor)&&(!o||e.visualization.drawToolbar)},getGoogleInstanceFromWindow=t=>window.google;function useLoadGoogleCharts(t){const{chartVersion:e="current",chartPackages:n=["corechart","controls"],chartLanguage:o="en",mapsApiKey:l}=t,[d,f]=React.useState(null),[g,b]=React.useState(null),[_,S]=React.useState(null),{isLoading:R,error:C,isSuccess:E}=useLoadScript(t.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return React.useEffect(()=>{if(!E)return;const A=getGoogleInstanceFromWindow();if(!isGoogleReady(A)){const M=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");b(M);return}if(isGoogleChartsReady(t,A)){f(A);return}A.charts.load(e,{packages:n,language:o,mapsApiKey:l}),A.charts.setOnLoadCallback(()=>{if(!isGoogleChartsReady(t,A)){const M=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(M),S(M);return}f(A)})},[E]),{error:C||g||_,isLoading:R,google:d}}const chartDefaultProps={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},GoogleChartControls=t=>{const{isReady:e,chartControls:n,filter:o}=t;return!e||!n||!(n!=null&&n.length)?null:React.createElement(React.Fragment,null,n.filter(l=>{let{controlProp:d,control:f}=l;return o?o({control:f,controlProp:d}):!0}).map(l=>{let{control:d}=l;return React.createElement("div",{key:d.getContainerId(),id:d.getContainerId()})}))};let uniqueID=0;const generateUniqueID=()=>(uniqueID+=1,`reactgooglegraph-${uniqueID}`),Mr=class Mr{};Qt(Mr,"initializeControls",e=>{for(let n=0;n<e.length;n+=1){const{controlType:o,options:l,controlWrapperParams:d}=e[n].controlProp;d&&"state"in d&&e[n].control.setState(d.state),e[n].control.setOptions(l),e[n].control.setControlType(o)}}),Qt(Mr,"listenToControlEvents",(e,n)=>{const{google:o}=n;return e.flatMap(l=>{const{control:d,controlProp:f}=l,{controlEvents:g=[]}=f;return g.map(b=>{const{callback:_,eventName:S}=b;return o.visualization.events.addListener(d,S,function(){for(var R=arguments.length,C=new Array(R),E=0;E<R;E++)C[E]=arguments[E];_({chartWrapper:null,controlWrapper:d,props:n,google:o,eventArgs:C})})})})}),Qt(Mr,"createControlId",e=>{let n;return typeof e>"u"?n=`googlechart-control-${generateUniqueID()}`:n=e,n}),Qt(Mr,"createChartControls",e=>{const{controls:n,google:o}=e;return n?n.map((l,d)=>{const{controlID:f,controlType:g,options:b,controlWrapperParams:_}=l,S=Mr.createControlId(f);return{controlProp:l,control:new o.visualization.ControlWrapper({containerId:S,controlType:g,options:b,..._})}}):null}),Qt(Mr,"addControls",e=>{const{chartWrapper:n,chartDashboard:o}=e,l=Mr.createChartControls(e);return!l||!o||!n?null:(o.bind(l.map(d=>{let{control:f}=d;return f}),n),Mr.initializeControls(l),l)});let GoogleChartControlsInternal=Mr;const useCreateChartControls=t=>{const[e,n]=React__namespace.useState(null);return[React__namespace.useMemo(()=>!e||!t?null:t.map((l,d)=>{const f=e[d];return f?{controlProp:l,control:f}:void 0}).flatMap(l=>l?[l]:[]),[e,t]),n]},useListenToControlEvents=(t,e)=>{React__namespace.useEffect(()=>{const n=GoogleChartControlsInternal.listenToControlEvents(t??[],e);return()=>{n.forEach(o=>{e.google.visualization.events.removeListener(o)})}},[t,e])},useChartControls=t=>{const[e,n]=useCreateChartControls(t.controls);return useListenToControlEvents(e??[],t),{addControls:l=>{const d=GoogleChartControlsInternal.addControls(l);n((d==null?void 0:d.map(f=>f.control))??null)},renderControl:l=>{const{chartWrapper:d,chartDashboard:f}=t;return React__namespace.createElement(GoogleChartControls,{...t,isReady:!!(d&&f),chartControls:e,filter:l})}}},useChartId=t=>{const e=React__namespace.useRef(null);return{chartId:(()=>{const{graphID:l,graph_id:d}=t,f=l||d;let g;return f?g=f:g=e.current||generateUniqueID(),e.current=g,e.current})()}},DEFAULT_CHART_COLORS=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],loadDataTableFromSpreadSheet=async function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((o,l)=>{const d=`${n.headers?`headers=${n.headers}`:"headers=0"}`,f=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,g=`${n.gid?`&gid=${n.gid}`:""}`,b=`${n.sheet?`&sheet=${n.sheet}`:""}`,_=`${n.access_token?`&access_token=${n.access_token}`:""}`,S=`${d}${g}${b}${f}${_}`,R=`${e}/gviz/tq?${S}`;new t.visualization.Query(R).send(E=>{E.isError()?l(`Error in query: ${E.getMessage()} ${E.getDetailedMessage()}`):o(E.getDataTable())})})},GRAY_COLOR="#CCCCCC",wr=class wr{};Qt(wr,"grayOutHiddenColumnsLabel",(e,n)=>{const{googleChartWrapper:o,options:l}=e;if(!o){console.error("googleChartWrapper is not defined");return}const d=o.getDataTable();if(!d)return;const f=d.getNumberOfColumns();if(n.length>0===!1)return;const b=Array.from({length:f-1}).map((_,S)=>{const R=wr.getColumnId(d,S+1);return n.includes(R)?GRAY_COLOR:l&&l.colors?l.colors[S]:DEFAULT_CHART_COLORS[S]});o.setOptions({...l,colors:b}),o.draw()}),Qt(wr,"listenToLegendToggle",(e,n)=>{const[o,l]=n,{google:d,googleChartWrapper:f}=e;if(!f){console.error("googleChartWrapper is not defined");return}return d.visualization.events.addListener(f,"select",()=>{const b=f.getChart().getSelection(),_=f.getDataTable();if(b.length===0||b[0].row!==null||!_)return;const S=b[0].column,R=wr.getColumnId(_,S);o!=null&&o.includes(R)?l(C=>[...C.filter(E=>E!==R)]):l(C=>[...C,R])})}),Qt(wr,"draw",async e=>{const{data:n,diffdata:o,rows:l,columns:d,options:f,chartType:g,formatters:b,spreadSheetUrl:_,spreadSheetQueryParameters:S,googleChartDashboard:R,googleChartWrapper:C,google:E,hiddenColumns:A,legendToggle:M,legend_toggle:I}=e;if(!C){console.error("draw was called with googleChartWrapper = null");return}let j,q=null;if(o){const te=E.visualization.arrayToDataTable(o.old),ne=E.visualization.arrayToDataTable(o.new);q=E.visualization[g].prototype.computeDiff(te,ne)}n?n instanceof E.visualization.DataTable?j=n:Array.isArray(n)?j=E.visualization.arrayToDataTable(n):j=new E.visualization.DataTable(n):l&&d?j=E.visualization.arrayToDataTable([d,...l]):_?j=await loadDataTableFromSpreadSheet(E,_,S):j=E.visualization.arrayToDataTable([]);const z=j.getNumberOfColumns(),Q=Array(z).fill(0).map((te,ne)=>{const se=wr.getColumnId(j,ne);return A.includes(se)?{label:j.getColumnLabel(ne),type:j.getColumnType(ne),calc:()=>null}:ne}),V=C.getChart();C.getChartType()==="Timeline"&&V&&V.clearChart(),C.setChartType(g),C.setOptions(f||{});const F=new E.visualization.DataView(j);F.setColumns(Q),C.setDataTable(F),C.draw(),R&&R.draw(j),q&&(C.setDataTable(q),C.draw()),b&&(wr.applyFormatters({dataTable:j,formatters:b,google:E}),C.setDataTable(j),C.draw()),(M===!0||I===!0)&&wr.grayOutHiddenColumnsLabel(e,A)}),Qt(wr,"getColumnId",(e,n)=>e.getColumnId(n)||e.getColumnLabel(n)),Qt(wr,"applyFormatters",e=>{let{dataTable:n,formatters:o,google:l}=e;for(let d of o)switch(d.type){case"ArrowFormat":{new l.visualization.ArrowFormat(d.options).format(n,d.column);return}case"BarFormat":{new l.visualization.BarFormat(d.options).format(n,d.column);return}case"ColorFormat":{const f=new l.visualization.ColorFormat(d.options),{ranges:g}=d;if(g)for(let b of g)f.addRange(...b);f.format(n,d.column);return}case"DateFormat":{new l.visualization.DateFormat(d.options).format(n,d.column);return}case"NumberFormat":{new l.visualization.NumberFormat(d.options).format(n,d.column);return}case"PatternFormat":{new l.visualization.PatternFormat(d.options).format(n,d.column);return}default:{console.warn(`Unknown formatter type: ${d.type}`);return}}});let GoogleChartInternal=wr;const useGoogleChartDataTable=t=>{const{google:e,googleChartWrapper:n,googleChartDashboard:o}=t,[l,d]=React__namespace.useState([]);React__namespace.useEffect(()=>{n&&GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:n,googleChartDashboard:o,google:e})},[l,t.data,t.rows,t.columns,t.options,t.chartLoaderScriptUrl,t.chartType,t.formatters,t.spreadSheetUrl,t.spreadSheetQueryParameters,t.legendToggle,t.legend_toggle]);const f=()=>{const{googleChartWrapper:_}=t;_&&_.draw()},g=_=>{const S=[],{legendToggle:R,legend_toggle:C}=t;if(GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:_,googleChartDashboard:o,google:e}),window.addEventListener("resize",f),C||R){const E=GoogleChartInternal.listenToLegendToggle(t,[l,d]);E&&S.push(E)}return S},b=(_,S)=>{window.removeEventListener("resize",f),S.forEach(R=>{e.visualization.events.removeListener(R)}),_.getChartType()==="Timeline"&&_.getChart()&&_.getChart().clearChart()};React__namespace.useEffect(()=>{if(!n)return;const _=g(n);return()=>{b(n,_)}},[n,g,b])},listenToEvents=t=>{const{chartEvents:e,google:n,googleChartWrapper:o}=t;if(e){if(!o){console.warn("listenToEvents was called before chart wrapper ready.");return}return e.map(l=>{let{eventName:d,callback:f}=l;return n.visualization.events.addListener(o,d,function(){for(var g=arguments.length,b=new Array(g),_=0;_<g;_++)b[_]=arguments[_];f({chartWrapper:o,props:t,google:n,eventArgs:b})})})}},useGoogleChartEvents=t=>{React.useEffect(()=>{if(!t.googleChartWrapper)return;const e=listenToEvents(t);return()=>{e==null||e.forEach(n=>{t.google.visualization.events.removeListener(n)})}},[t])},GoogleChart=t=>{const[e,n]=React__namespace.useState(null),[o,l]=React__namespace.useState(null),{addControls:d,renderControl:f}=useChartControls({...t,chartDashboard:o,chartWrapper:e});useGoogleChartEvents({...t,googleChartWrapper:e});const{chartId:g}=useChartId(t),b=React__namespace.useRef(null),_=React__namespace.useRef(null);React__namespace.useEffect(()=>{const{options:j,google:q,chartType:z,chartWrapperParams:Q,toolbarItems:V,getChartEditor:F,getChartWrapper:te,onLoad:ne}=t,se={chartType:z,options:j,containerId:g,...Q},ge=new q.visualization.ChartWrapper(se);ge.setOptions(j||{}),te==null||te(ge,q);const oe=new q.visualization.Dashboard(b.current);V&&q.visualization.drawToolbar(_.current,V);let Ae=null;F&&(Ae=new q.visualization.ChartEditor,F({chartEditor:Ae,chartWrapper:ge,google:q})),d({...t,chartDashboard:oe,chartWrapper:ge}),n(ge),l(oe),ne==null||ne(q,{google:q,chartWrapper:ge,chartEditor:Ae,chartDashboard:oe})},[]),useGoogleChartDataTable({...t,googleChartWrapper:e,googleChartDashboard:o});const S=()=>{const{width:j,height:q,options:z,style:Q,className:V,rootProps:F,google:te}=t,ne={height:q||z&&z.height,width:j||z&&z.width,...Q};return React__namespace.createElement("div",{id:g,style:ne,className:V,...F})},R=()=>t.toolbarItems?React__namespace.createElement("div",{ref:_}):null,{width:C,height:E,options:A,style:M}=t,I={height:E||A&&A.height,width:C||A&&A.width,...M};return t.render?React__namespace.createElement("div",{ref:b,style:I},React__namespace.createElement("div",{ref:_,id:"toolbar"}),t.render({renderChart:S,renderControl:f,renderToolbar:R})):React__namespace.createElement("div",{ref:b,style:I},f(j=>{let{controlProp:q}=j;return q.controlPosition!=="bottom"}),S(),f(j=>{let{controlProp:q}=j;return q.controlPosition==="bottom"}),R())},ChartContext=React__namespace.createContext(chartDefaultProps),ContextProvider=t=>{let{children:e,value:n}=t;return React__namespace.createElement(ChartContext.Provider,{value:n},e)},ChartView=t=>{const{google:e,isLoading:n,error:o}=useLoadGoogleCharts(t);return n?t.loader??null:o?t.errorElement??null:e?React.createElement(GoogleChart,{google:e,...t}):null},Chart=t=>{const e={...chartDefaultProps,...t};return React.createElement(ContextProvider,{value:e},React.createElement(ChartView,e))};var GoogleDataTableColumnRoleType;(function(t){t.annotation="annotation",t.annotationText="annotationText",t.certainty="certainty",t.emphasis="emphasis",t.interval="interval",t.scope="scope",t.style="style",t.tooltip="tooltip",t.domain="domain"})(GoogleDataTableColumnRoleType||(GoogleDataTableColumnRoleType={}));function parseHsl(t){const e=t.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return e?{h:parseFloat(e[1]),s:parseFloat(e[2]),l:parseFloat(e[3])}:null}function hslToHex(t,e,n){n/=100;const o=e*Math.min(n,1-n)/100,l=d=>{const f=(d+t/30)%12,g=n-o*Math.max(Math.min(f-3,9-f,1),-1);return Math.round(255*g).toString(16).padStart(2,"0")};return`#${l(0)}${l(8)}${l(4)}`}const Treemap=React__namespace.forwardRef(({data:t,options:e,height:n="500px",className:o,loading:l,disableClick:d=!0,...f},g)=>{const b=React__namespace.useRef(null),[_,S]=React__namespace.useState(null);React__namespace.useEffect(()=>{if(!b.current)return;const E=b.current,A=()=>{const q=getComputedStyle(E).getPropertyValue("--primary").trim();if(q){const z=parseHsl(q);if(z){const{h:Q,s:V,l:F}=z;S({minColor:hslToHex(Q,V,Math.min(100,F+50)),midColor:hslToHex(Q,V,Math.min(100,F+35)),maxColor:hslToHex(Q,V,Math.min(100,F+20))})}return!0}return!1};if(A())return;let M=0;const I=20,j=setInterval(()=>{(A()||M>=I)&&clearInterval(j),M++},100);return()=>{j&&clearInterval(j)}},[]);const R=React__namespace.useMemo(()=>{const E={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"hsl(var(--background))",generateTooltip:(A,M)=>{var q;const I=(q=t[A+1])==null?void 0:q[0];if(!I)return"";const j=formatMoney(M);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
1353
1353
  <strong>${I}</strong><br>Value: ${j}
1354
- </div>`}};return _&&(!e||!e.colorAxis)&&(E.minColor=_.minColor,E.midColor=_.midColor,E.maxColor=_.maxColor),{...E,...e}},[t,e,_]),C=React__namespace.useMemo(()=>d?[{eventName:"select",callback:({chartWrapper:A})=>{A.getChart().setSelection(null)}}]:void 0,[d]);return React__namespace.useImperativeHandle(g,()=>b.current,[]),l?jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})}):!t||t.length<=2?jsxRuntime.jsx("div",{ref:b,className:cn("w-full flex items-center justify-center text-muted-foreground",o),style:{height:n},...f,children:"No data available"}):jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:t,options:R,chartEvents:C,loader:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})})})});Treemap.displayName="Treemap";const TopPercentTreemap=({data:t,topPercent:e=80,title:n,loading:o,...l})=>{const d=React__namespace.useMemo(()=>{if(!t||t.length===0)return[["ID","Parent","Value"],["Root",null,0]];const g=[...t].sort((A,M)=>M.value-A.value),_=g.reduce((A,M)=>A+M.value,0)*(e/100),S=[["ID","Parent","Value"],["Root",null,0]],R=[],C=[];let E=0;for(const A of g)E<_?(R.push(A),E+=A.value):C.push(A);if(R.forEach(A=>{S.push([A.name,"Root",A.value])}),C.length>0){const A=`More... (${C.length} items)`;S.push([A,"Root",0]),C.forEach(M=>{S.push([M.name,A,M.value])})}return S},[t,e]),f=React__namespace.useMemo(()=>({title:n,maxDepth:1,backgroundColor:"hsl(var(--background))"}),[n]);return jsxRuntime.jsx(Treemap,{data:d,options:f,className:cn("h-full",l.className),loading:o,disableClick:!1,...l})};function ExternalProductCard({product:t,viewProductLink:e}){return t?jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @md:flex-row",children:[jsxRuntime.jsx("div",{className:"mx-auto flex-shrink-0 @md:mx-0 @md:w-48",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col text-center @md:text-left",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @md:hidden",children:[jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-orange-300 bg-orange-50 text-orange-800",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-randmar-red bg-red-50 text-randmar-red",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),jsxRuntime.jsxs("div",{className:"hidden @md:grid grid-cols-2 gap-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-orange-50 px-4 py-2 text-orange-800 border-1 border-orange-800 text-sm",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-red-50 px-4 py-2 text-randmar-red border-1 border-randmar-red text-sm",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),e&&jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @md:justify-end",children:jsxRuntime.jsx(reactRouterDom.Link,{to:e,children:jsxRuntime.jsxs(Button,{variant:"secondary",className:"w-full @md:w-auto",children:[jsxRuntime.jsx(Eye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})})}):jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-6 flex-grow @md:flex-row",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 @md:w-48",children:jsxRuntime.jsx(Skeleton,{className:"aspect-square w-full h-auto"})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-1/2"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @md:hidden",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"hidden @md:grid grid-cols-2 gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"})]})]}),jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @md:justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-full @md:w-40"})})]})]})})})}const resultCache=new Map,requestCache=new Map;function cleanHtmlString(t){let e=t.trim();return e.startsWith("```html")&&(e=e.substring(7).trim()),e.endsWith("```")&&(e=e.slice(0,-3).trim()),e}const GetTextInsightFromAI=async(t,e,n,o=3)=>{const l=`
1355
- Analyze the following prompt and provide a helpful, concise response formatted in simple HTML.
1354
+ </div>`}};return _&&(!e||!e.colorAxis)&&(E.minColor=_.minColor,E.midColor=_.midColor,E.maxColor=_.maxColor),{...E,...e}},[t,e,_]),C=React__namespace.useMemo(()=>d?[{eventName:"select",callback:({chartWrapper:A})=>{A.getChart().setSelection(null)}}]:void 0,[d]);return React__namespace.useImperativeHandle(g,()=>b.current,[]),l?jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})}):!t||t.length<=2?jsxRuntime.jsx("div",{ref:b,className:cn("w-full flex items-center justify-center text-muted-foreground",o),style:{height:n},...f,children:"No data available"}):jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:t,options:R,chartEvents:C,loader:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})})})});Treemap.displayName="Treemap";const TopPercentTreemap=({data:t,topPercent:e=80,title:n,loading:o,...l})=>{const d=React__namespace.useMemo(()=>{if(!t||t.length===0)return[["ID","Parent","Value"],["Root",null,0]];const g=[...t].sort((A,M)=>M.value-A.value),_=g.reduce((A,M)=>A+M.value,0)*(e/100),S=[["ID","Parent","Value"],["Root",null,0]],R=[],C=[];let E=0;for(const A of g)E<_?(R.push(A),E+=A.value):C.push(A);if(R.forEach(A=>{S.push([A.name,"Root",A.value])}),C.length>0){const A=`More... (${C.length} items)`;S.push([A,"Root",0]),C.forEach(M=>{S.push([M.name,A,M.value])})}return S},[t,e]),f=React__namespace.useMemo(()=>({title:n,maxDepth:1,backgroundColor:"hsl(var(--background))"}),[n]);return jsxRuntime.jsx(Treemap,{data:d,options:f,className:cn("h-full",l.className),loading:o,disableClick:!1,...l})};function ExternalProductCard({product:t,viewProductLink:e}){return t?jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @md:flex-row",children:[jsxRuntime.jsx("div",{className:"mx-auto flex-shrink-0 @md:mx-0 @md:w-48",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col text-center @md:text-left",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @md:hidden",children:[jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-orange-300 bg-orange-50 text-orange-800",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-randmar-red bg-red-50 text-randmar-red",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),jsxRuntime.jsxs("div",{className:"hidden @md:grid grid-cols-2 gap-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-orange-50 px-4 py-2 text-orange-800 border-1 border-orange-800 text-sm",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-red-50 px-4 py-2 text-randmar-red border-1 border-randmar-red text-sm",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),e&&jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @md:justify-end",children:jsxRuntime.jsx(reactRouterDom.Link,{to:e,children:jsxRuntime.jsxs(Button,{variant:"secondary",className:"w-full @md:w-auto",children:[jsxRuntime.jsx(Eye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})})}):jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-6 flex-grow @md:flex-row",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 @md:w-48",children:jsxRuntime.jsx(Skeleton,{className:"aspect-square w-full h-auto"})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-1/2"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @md:hidden",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"hidden @md:grid grid-cols-2 gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"})]})]}),jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @md:justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-full @md:w-40"})})]})]})})})}const resultCache=new Map,requestCache=new Map;function cleanResponseString(t,e){const n=t.trim();if(e==="text")return n;const o=/^```(?:\w+\n)?([\s\S]+)\n```$/,l=n.match(o);return l?l[1].trim():n}const fetchGeminiResponse=async(t,e,n,o,l=3)=>{const f=`
1355
+ Analyze the following prompt and ${o==="html"?`Provide a helpful, concise response formatted in simple HTML.
1356
1356
  - Use <p> tags for paragraphs.
1357
1357
  - Use <strong> for emphasis.
1358
1358
  - You can also use ordered (<ol>) and unordered (<ul>) lists with list items (<li>).
1359
- - Do not include <html>, <head>, <body>, or markdown \`\`\` fences. Output only the content itself.
1359
+ - Do not include <html>, <head>, <body>, or markdown \`\`\` fences. Output only the content itself.`:"Provide a helpful, concise response in plain text. Do not use any HTML tags or markdown formatting."}
1360
1360
  ---
1361
1361
  Prompt: "${e}"
1362
- `;try{const d=new GoogleGenAI({apiKey:t}),f=n?"gemini-2.5-pro":"gemini-2.5-flash";return(await d.chats.create({model:f}).sendMessage({message:l})).text??"<p>Sorry, I couldn't generate a response for this.</p>"}catch(d){return console.error("Error fetching AI insight:",d),o>0?(await new Promise(f=>setTimeout(f,(4-o)*500)),GetTextInsightFromAI(t,e,n,o-1)):"<p>An error occurred while generating the insight.</p>"}};function AssistantInsight({prompt:t,smartAndSlow:e=!1,thinkingPlaceholderText:n="Thinking..."}){const[o,l]=React.useState(""),[d,f]=React.useState(!0),[g,b]=React.useState(null),{apiKey:_}=useGeminiApiKey();return React.useEffect(()=>{let S=!1;return(async()=>{if(!_||!t){if(S)return;b("Prompt and API Key are required."),f(!1);return}if(resultCache.has(t)){if(S)return;l(resultCache.get(t)),f(!1);return}if(requestCache.has(t)){if(S)return;f(!0),await requestCache.get(t),!S&&resultCache.has(t)&&l(resultCache.get(t)),S||f(!1);return}try{if(S)return;f(!0);const C=GetTextInsightFromAI(_,t,e).then(E=>{const A=cleanHtmlString(E);resultCache.set(t,A)});if(requestCache.set(t,C),await C,S)return;resultCache.has(t)&&l(resultCache.get(t))}catch(C){if(S)return;const E=C instanceof Error?C.message:"An unknown error occurred.";b(E),console.error(C)}finally{requestCache.delete(t),S||f(!1)}})(),()=>{S=!0}},[t,_,e]),jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg bg-background",children:[jsxRuntime.jsx(Bot,{className:`mt-1 h-6 w-6 flex-shrink-0 ${d?"animate-pulse text-primary":"text-primary"}`}),jsxRuntime.jsxs("div",{className:"w-full min-h-[4rem]",children:[d&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"font-medium text-muted-foreground",children:n}),jsxRuntime.jsxs("div",{className:"space-y-2 mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-5/6"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-3/4"})]})]}),g&&jsxRuntime.jsx("p",{className:"text-sm text-red-600",children:g}),!d&&!g&&o&&jsxRuntime.jsx("div",{className:"chat-bubble-in-animation text-sm text-foreground space-y-4",dangerouslySetInnerHTML:{__html:o}})]})]})}exports.ActiveOrdersCard=ActiveOrdersCard,exports.AiGeneratedContent=AiGeneratedContent,exports.Alert=Alert,exports.AlertDescription=AlertDescription,exports.AlertDialog=AlertDialog,exports.AlertDialogAction=AlertDialogAction,exports.AlertDialogCancel=AlertDialogCancel,exports.AlertDialogContent=AlertDialogContent,exports.AlertDialogDescription=AlertDialogDescription,exports.AlertDialogFooter=AlertDialogFooter,exports.AlertDialogHeader=AlertDialogHeader,exports.AlertDialogTitle=AlertDialogTitle,exports.AlertDialogTrigger=AlertDialogTrigger,exports.AlertTitle=AlertTitle,exports.AreaChart=AreaChart,exports.AssistantChat=AssistantChat,exports.AssistantInsight=AssistantInsight,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.ExternalProductCard=ExternalProductCard,exports.GeminiApiKeyProvider=GeminiApiKeyProvider,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.OpportunitiesTable=OpportunitiesTable,exports.PageHeader=PageHeader,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.ProductOverviewPage=ProductOverviewPage,exports.Progress=Progress,exports.RadioGroup=RadioGroup$1,exports.RadioGroupItem=RadioGroupItem,exports.ResellerBillingOverviewCard=ResellerBillingOverviewCard,exports.ResellerCard=ResellerCard,exports.ResellerOverview=ResellerOverview,exports.ResellerQualificationsCard=ResellerQualificationsCard,exports.ReturnsTable=ReturnsTable,exports.RichTextEditor=RichTextEditor,exports.SalesChart=SalesChart,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.TopPercentTreemap=TopPercentTreemap,exports.Topbar=Topbar,exports.Treemap=Treemap,exports.badgeVariants=badgeVariants,exports.buttonVariants=buttonVariants,exports.formatMoney=formatMoney,exports.formatNumber=formatNumber,exports.formatYYYYMMDDIntToDateString=formatYYYYMMDDIntToDateString,exports.toast=toast,exports.useChat=useChat,exports.useGeminiApiKey=useGeminiApiKey,exports.useIsMobile=useIsMobile,exports.useSidebar=useSidebar,exports.useToast=useToast,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
1362
+ `;try{const g=new GoogleGenAI({apiKey:t}),b=n?"gemini-1.5-pro-latest":"gemini-1.5-flash-latest";return(await g.chats.create({model:b}).sendMessage({message:f})).text??"Sorry, I couldn't generate a response for this."}catch(g){return console.error("Error fetching AI response:",g),l>0?(await new Promise(b=>setTimeout(b,(4-l)*500)),fetchGeminiResponse(t,e,n,o,l-1)):"An error occurred while generating the response."}},useGemini=(t={})=>{const{useProModel:e=!1,outputFormat:n="html"}=t,[o,l]=React.useState(null),[d,f]=React.useState(!1),[g,b]=React.useState(null),{apiKey:_}=useGeminiApiKey(),S=React.useRef(null),R=React.useCallback(async C=>{if(!_){b("API Key is required.");return}S.current=C;const E=`${C}::${n}`;if(resultCache.has(E)){l(resultCache.get(E)),f(!1),b(null);return}if(requestCache.has(E)){f(!0);try{await requestCache.get(E),S.current===C&&l(resultCache.get(E))}catch(M){S.current===C&&b(M instanceof Error?M.message:"An unknown error occurred.")}finally{S.current===C&&f(!1)}return}f(!0),b(null);const A=fetchGeminiResponse(_,C,e,n).then(M=>{const I=cleanResponseString(M,n);return resultCache.set(E,I),I}).catch(M=>{throw requestCache.delete(E),M});requestCache.set(E,A);try{const M=await A;S.current===C&&l(M)}catch(M){S.current===C&&b(M instanceof Error?M.message:"An unknown error occurred.")}finally{requestCache.delete(E),S.current===C&&f(!1)}},[_,e,n]);return{response:o,isLoading:d,error:g,sendPrompt:R}};function AssistantInsight({prompt:t,smartAndSlow:e=!1,thinkingPlaceholderText:n="Thinking..."}){const{response:o,isLoading:l,error:d,sendPrompt:f}=useGemini({useProModel:e,outputFormat:"html"});return React.useEffect(()=>{t&&f(t)},[t,f]),jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg bg-background",children:[jsxRuntime.jsx(Bot,{className:`mt-1 h-6 w-6 flex-shrink-0 ${l?"animate-pulse text-primary":"text-primary"}`}),jsxRuntime.jsxs("div",{className:"w-full min-h-[4rem]",children:[l&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"font-medium text-muted-foreground",children:n}),jsxRuntime.jsxs("div",{className:"space-y-2 mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-5/6"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-3/4"})]})]}),d&&jsxRuntime.jsx("p",{className:"text-sm text-red-600",children:d}),!l&&!d&&o&&jsxRuntime.jsx("div",{className:"chat-bubble-in-animation text-sm text-foreground space-y-4",dangerouslySetInnerHTML:{__html:o}})]})]})}exports.ActiveOrdersCard=ActiveOrdersCard,exports.AiGeneratedContent=AiGeneratedContent,exports.Alert=Alert,exports.AlertDescription=AlertDescription,exports.AlertDialog=AlertDialog,exports.AlertDialogAction=AlertDialogAction,exports.AlertDialogCancel=AlertDialogCancel,exports.AlertDialogContent=AlertDialogContent,exports.AlertDialogDescription=AlertDialogDescription,exports.AlertDialogFooter=AlertDialogFooter,exports.AlertDialogHeader=AlertDialogHeader,exports.AlertDialogTitle=AlertDialogTitle,exports.AlertDialogTrigger=AlertDialogTrigger,exports.AlertTitle=AlertTitle,exports.AreaChart=AreaChart,exports.AssistantChat=AssistantChat,exports.AssistantInsight=AssistantInsight,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.ExternalProductCard=ExternalProductCard,exports.GeminiApiKeyProvider=GeminiApiKeyProvider,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.OpportunitiesTable=OpportunitiesTable,exports.PageHeader=PageHeader,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.ProductOverviewPage=ProductOverviewPage,exports.Progress=Progress,exports.RadioGroup=RadioGroup$1,exports.RadioGroupItem=RadioGroupItem,exports.ResellerBillingOverviewCard=ResellerBillingOverviewCard,exports.ResellerCard=ResellerCard,exports.ResellerOverview=ResellerOverview,exports.ResellerQualificationsCard=ResellerQualificationsCard,exports.ReturnsTable=ReturnsTable,exports.RichTextEditor=RichTextEditor,exports.SalesChart=SalesChart,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.TopPercentTreemap=TopPercentTreemap,exports.Topbar=Topbar,exports.Treemap=Treemap,exports.badgeVariants=badgeVariants,exports.buttonVariants=buttonVariants,exports.formatMoney=formatMoney,exports.formatNumber=formatNumber,exports.formatYYYYMMDDIntToDateString=formatYYYYMMDDIntToDateString,exports.toast=toast,exports.useChat=useChat,exports.useGeminiApiKey=useGeminiApiKey,exports.useIsMobile=useIsMobile,exports.useSidebar=useSidebar,exports.useToast=useToast,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "randmarcomps",
3
3
  "private": false,
4
- "version": "1.337.0",
4
+ "version": "1.340.0",
5
5
  "description": "The UI library enabling speed and consistency in Randmar frontends.",
6
6
  "type": "module",
7
7
  "files": [