randmarcomps 1.289.0 → 1.290.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.
@@ -60609,7 +60609,7 @@ const DebugMessageDisplay = ({ debugMessages: t }) => {
60609
60609
  ] })
60610
60610
  ] }) })
60611
60611
  ] }),
60612
- /* @__PURE__ */ jsx("div", { className: "mt-1 mb-1", children: qe.findIndex((Ct) => Ct.partner1 === "2" || Ct.partner2 === "2") < 0 ? /* @__PURE__ */ jsx(Button, { className: "w-full", ref: A, onClick: () => Yt(), children: "Chat with Randmar" }, "b1") : /* @__PURE__ */ jsx("a", { target: "_blank", href: `https://dashboard.randmar.io/${t}/ExploreManufacturers`, children: /* @__PURE__ */ jsx(Button, { className: "w-full", children: "Explore manufacturers" }, "b2") }) }),
60612
+ /* @__PURE__ */ jsx("div", { className: "mt-1 mb-1", children: qe.findIndex((Ct) => Ct.partner1 === "2" || Ct.partner2 === "2") < 0 ? /* @__PURE__ */ jsx(Button, { className: "w-full", ref: A, onClick: () => Yt(), children: "Chat with Randmar" }, "b1") : ge === "approved" && qe.length >= 5 ? null : /* @__PURE__ */ jsx("a", { target: "_blank", href: `https://dashboard.randmar.io/${t}/ExploreManufacturers`, children: /* @__PURE__ */ jsx(Button, { className: "w-full", children: "Explore manufacturers" }, "b2") }) }),
60613
60613
  /* @__PURE__ */ jsx(ScrollArea, { className: "flex-1", children: qe.length && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(ChatList, { userId: t, chats: Ht.filter((Ct) => Ct.partner1 != ASSISTANT_ID && Ct.partner2 != ASSISTANT_ID), activeChat: mt ?? null, onSelectChat: $e, assistantChat: qe.find((Ct) => Ct.partner1 == ASSISTANT_ID || Ct.partner2 == ASSISTANT_ID) }) }) })
60614
60614
  ] }) }),
60615
60615
  /* @__PURE__ */ jsx("div", { className: "flex-5 flex flex-col", children: Ae ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -63505,50 +63505,50 @@ function PartnerRelationshipPage({
63505
63505
  shopifyHostName: o,
63506
63506
  isSuperAdmin: l
63507
63507
  }) {
63508
- var I, M, O;
63509
- const { data: d, isLoading: f } = useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({
63508
+ var O, q, z;
63509
+ const { data: d, isLoading: f, isFetching: g } = useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({
63510
63510
  routeApplicationId: t,
63511
63511
  partnerId: e,
63512
63512
  withSpecification: !0
63513
- }), { toast: g } = useToast(), [b] = usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(), [S, _] = useState(!1), [C, E] = useState(!1), R = async () => {
63513
+ }), b = f || g, { toast: S } = useToast(), [_] = usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(), [C, E] = useState(!1), [R, A] = useState(!1), I = async () => {
63514
63514
  try {
63515
- _(!0), E(!1), await b({
63515
+ E(!0), A(!1), await _({
63516
63516
  routeResellerId: t ?? "",
63517
63517
  manufacturerId: e ?? "",
63518
63518
  shopifyHostName: o
63519
- }).unwrap() && g({
63519
+ }).unwrap() && S({
63520
63520
  title: "Success",
63521
63521
  description: "Manufacturer synced to Shopify successfully",
63522
63522
  variant: "success"
63523
63523
  });
63524
- } catch (q) {
63525
- console.error("Error syncing to Shopify:", q), g({
63524
+ } catch (Q) {
63525
+ console.error("Error syncing to Shopify:", Q), S({
63526
63526
  title: "Error",
63527
63527
  description: "Error syncing manufacturer to Shopify.",
63528
63528
  variant: "destructive"
63529
63529
  });
63530
63530
  } finally {
63531
- _(!1);
63531
+ E(!1);
63532
63532
  }
63533
- }, A = () => d != null && d.Reseller ? "reseller-overview" : d != null && d.Manufacturer ? "manufacturer-overview" : "";
63533
+ }, M = () => d != null && d.Reseller ? "reseller-overview" : d != null && d.Manufacturer ? "manufacturer-overview" : "";
63534
63534
  return /* @__PURE__ */ jsxs("div", { className: "@container", children: [
63535
63535
  /* @__PURE__ */ jsxs("div", { className: "grid gap-4 @2xl:grid-cols-2", children: [
63536
63536
  /* @__PURE__ */ jsx(
63537
63537
  PartnerCard,
63538
63538
  {
63539
63539
  account: d,
63540
- loading: f,
63540
+ loading: b,
63541
63541
  withAbout: !0,
63542
63542
  withVoice: !1,
63543
63543
  action: " "
63544
63544
  }
63545
63545
  ),
63546
63546
  /* @__PURE__ */ jsxs("div", { className: "grid gap-4", children: [
63547
- ((d == null ? void 0 : d.Manufacturer) || f) && /* @__PURE__ */ jsx(
63547
+ ((d == null ? void 0 : d.Manufacturer) || b) && /* @__PURE__ */ jsx(
63548
63548
  ManufacturerCard,
63549
63549
  {
63550
63550
  manufacturer: d == null ? void 0 : d.Manufacturer,
63551
- loading: f,
63551
+ loading: b,
63552
63552
  mainAction: /* @__PURE__ */ jsxs(Fragment$1, { children: [
63553
63553
  (d == null ? void 0 : d.Manufacturer) && /* @__PURE__ */ jsx(
63554
63554
  ManufacturerGetStartedButton,
@@ -63557,8 +63557,8 @@ function PartnerRelationshipPage({
63557
63557
  manufacturer: d == null ? void 0 : d.Manufacturer
63558
63558
  }
63559
63559
  ),
63560
- o && ((M = (I = d == null ? void 0 : d.Manufacturer) == null ? void 0 : I.Categories) == null ? void 0 : M.findIndex((q) => q.AvailableToBuy)) !== -1 && /* @__PURE__ */ jsxs(Dialog, { open: C, onOpenChange: E, children: [
63561
- /* @__PURE__ */ jsx(DialogTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(Button, { className: "bg-green-600 hover:bg-green-700 ml-2", disabled: S, children: S ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
63560
+ o && ((q = (O = d == null ? void 0 : d.Manufacturer) == null ? void 0 : O.Categories) == null ? void 0 : q.findIndex((Q) => Q.AvailableToBuy)) !== -1 && /* @__PURE__ */ jsxs(Dialog, { open: R, onOpenChange: A, children: [
63561
+ /* @__PURE__ */ jsx(DialogTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(Button, { className: "bg-green-600 hover:bg-green-700 ml-2", disabled: C, children: C ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
63562
63562
  /* @__PURE__ */ jsx(LoaderCircle, { className: "mr-2 h-4 w-4 animate-spin" }),
63563
63563
  "Syncing..."
63564
63564
  ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -63570,19 +63570,19 @@ function PartnerRelationshipPage({
63570
63570
  /* @__PURE__ */ jsx(DialogTitle, { children: "Confirm Sync to Shopify" }),
63571
63571
  /* @__PURE__ */ jsxs(DialogDescription, { children: [
63572
63572
  'Are you sure you want to sync the manufacturer "',
63573
- (O = d == null ? void 0 : d.Manufacturer) == null ? void 0 : O.PublicName,
63573
+ (z = d == null ? void 0 : d.Manufacturer) == null ? void 0 : z.PublicName,
63574
63574
  '" to Shopify? This will add all products from this manufacturer to your Shopify store.'
63575
63575
  ] })
63576
63576
  ] }),
63577
63577
  /* @__PURE__ */ jsxs(DialogFooter, { children: [
63578
- /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => E(!1), children: "Cancel" }),
63578
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => A(!1), children: "Cancel" }),
63579
63579
  /* @__PURE__ */ jsx(
63580
63580
  Button,
63581
63581
  {
63582
63582
  className: "bg-green-600 hover:bg-green-700",
63583
- onClick: R,
63584
- disabled: S,
63585
- children: S ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
63583
+ onClick: I,
63584
+ disabled: C,
63585
+ children: C ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
63586
63586
  /* @__PURE__ */ jsx(LoaderCircle, { className: "mr-2 h-4 w-4 animate-spin" }),
63587
63587
  "Syncing..."
63588
63588
  ] }) : "Confirm Sync"
@@ -63594,10 +63594,10 @@ function PartnerRelationshipPage({
63594
63594
  ] })
63595
63595
  }
63596
63596
  ),
63597
- (d == null ? void 0 : d.Reseller) && /* @__PURE__ */ jsx(ResellerCard, { reseller: d == null ? void 0 : d.Reseller, loading: f })
63597
+ (d == null ? void 0 : d.Reseller) && /* @__PURE__ */ jsx(ResellerCard, { reseller: d == null ? void 0 : d.Reseller, loading: b })
63598
63598
  ] })
63599
63599
  ] }),
63600
- ((d == null ? void 0 : d.Reseller) || (d == null ? void 0 : d.Manufacturer)) && !f && /* @__PURE__ */ jsx("div", { className: "max-w-6xl mx-auto p-4", children: /* @__PURE__ */ jsxs(Tabs, { defaultValue: A(), className: "w-full", children: [
63600
+ ((d == null ? void 0 : d.Reseller) || (d == null ? void 0 : d.Manufacturer)) && !b && /* @__PURE__ */ jsx("div", { className: "max-w-6xl mx-auto p-4", children: /* @__PURE__ */ jsxs(Tabs, { defaultValue: M(), className: "w-full", children: [
63601
63601
  /* @__PURE__ */ jsxs(TabsList, { className: "inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0", children: [
63602
63602
  (d == null ? void 0 : d.Reseller) && /* @__PURE__ */ jsx(
63603
63603
  TabsTrigger,
@@ -63653,7 +63653,7 @@ function PartnerRelationshipPage({
63653
63653
  }
63654
63654
  ) }) })
63655
63655
  ] }) }),
63656
- f && /* @__PURE__ */ jsx("div", { className: "max-w-6xl mx-auto p-4 mt-4 flex justify-center items-center h-32", children: /* @__PURE__ */ jsx(LoaderCircle, { className: "h-8 w-8 animate-spin text-primary" }) })
63656
+ b && /* @__PURE__ */ jsx("div", { className: "max-w-6xl mx-auto p-4 mt-4 flex justify-center items-center h-32", children: /* @__PURE__ */ jsx(LoaderCircle, { className: "h-8 w-8 animate-spin text-primary" }) })
63657
63657
  ] });
63658
63658
  }
63659
63659
  const PublicInfo = ({ reseller: t, appID: e, isLoading: n, readonly: o, onUnsavedChanges: l }) => {
@@ -1050,7 +1050,7 @@ ${t}</tr>
1050
1050
  `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${escape2(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){const o=this.parser.parseInline(n),l=cleanUrl(t);if(l===null)return o;t=l;let d='<a href="'+t+'"';return e&&(d+=' title="'+escape2(e)+'"'),d+=">"+o+"</a>",d}image({href:t,title:e,text:n,tokens:o}){o&&(n=this.parser.parseInline(o,this.parser.textRenderer));const l=cleanUrl(t);if(l===null)return escape2(n);t=l;let d=`<img src="${t}" alt="${n}"`;return e&&(d+=` title="${escape2(e)}"`),d+=">",d}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:escape2(t.text)}},_TextRenderer=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}},_Parser=class gn{constructor(e){ir(this,"options");ir(this,"renderer");ir(this,"textRenderer");this.options=e||_defaults,this.options.renderer=this.options.renderer||new _Renderer,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new _TextRenderer}static parse(e,n){return new gn(n).parse(e)}static parseInline(e,n){return new gn(n).parseInline(e)}parse(e,n=!0){var l,d;let o="";for(let f=0;f<e.length;f++){const g=e[f];if((d=(l=this.options.extensions)==null?void 0:l.renderers)!=null&&d[g.type]){const _=g,S=this.options.extensions.renderers[_.type].call({parser:this},_);if(S!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(_.type)){o+=S||"";continue}}const b=g;switch(b.type){case"space":{o+=this.renderer.space(b);continue}case"hr":{o+=this.renderer.hr(b);continue}case"heading":{o+=this.renderer.heading(b);continue}case"code":{o+=this.renderer.code(b);continue}case"table":{o+=this.renderer.table(b);continue}case"blockquote":{o+=this.renderer.blockquote(b);continue}case"list":{o+=this.renderer.list(b);continue}case"html":{o+=this.renderer.html(b);continue}case"paragraph":{o+=this.renderer.paragraph(b);continue}case"text":{let _=b,S=this.renderer.text(_);for(;f+1<e.length&&e[f+1].type==="text";)_=e[++f],S+=`
1051
1051
  `+this.renderer.text(_);n?o+=this.renderer.paragraph({type:"paragraph",raw:S,text:S,tokens:[{type:"text",raw:S,text:S,escaped:!0}]}):o+=S;continue}default:{const _='Token with "'+b.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw new Error(_)}}}return o}parseInline(e,n=this.renderer){var l,d;let o="";for(let f=0;f<e.length;f++){const g=e[f];if((d=(l=this.options.extensions)==null?void 0:l.renderers)!=null&&d[g.type]){const _=this.options.extensions.renderers[g.type].call({parser:this},g);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(g.type)){o+=_||"";continue}}const b=g;switch(b.type){case"escape":{o+=n.text(b);break}case"html":{o+=n.html(b);break}case"link":{o+=n.link(b);break}case"image":{o+=n.image(b);break}case"strong":{o+=n.strong(b);break}case"em":{o+=n.em(b);break}case"codespan":{o+=n.codespan(b);break}case"br":{o+=n.br(b);break}case"del":{o+=n.del(b);break}case"text":{o+=n.text(b);break}default:{const _='Token with "'+b.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw new Error(_)}}}return o}},_Hooks=(sr=class{constructor(t){ir(this,"options");ir(this,"block");this.options=t||_defaults}preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}provideLexer(){return this.block?_Lexer.lex:_Lexer.lexInline}provideParser(){return this.block?_Parser.parse:_Parser.parseInline}},ir(sr,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),sr),Marked=class{constructor(...t){ir(this,"defaults",_getDefaults());ir(this,"options",this.setOptions);ir(this,"parse",this.parseMarkdown(!0));ir(this,"parseInline",this.parseMarkdown(!1));ir(this,"Parser",_Parser);ir(this,"Renderer",_Renderer);ir(this,"TextRenderer",_TextRenderer);ir(this,"Lexer",_Lexer);ir(this,"Tokenizer",_Tokenizer);ir(this,"Hooks",_Hooks);this.use(...t)}walkTokens(t,e){var o,l;let n=[];for(const d of t)switch(n=n.concat(e.call(this,d)),d.type){case"table":{const f=d;for(const g of f.header)n=n.concat(this.walkTokens(g.tokens,e));for(const g of f.rows)for(const b of g)n=n.concat(this.walkTokens(b.tokens,e));break}case"list":{const f=d;n=n.concat(this.walkTokens(f.items,e));break}default:{const f=d;(l=(o=this.defaults.extensions)==null?void 0:o.childTokens)!=null&&l[f.type]?this.defaults.extensions.childTokens[f.type].forEach(g=>{const b=f[g].flat(1/0);n=n.concat(this.walkTokens(b,e))}):f.tokens&&(n=n.concat(this.walkTokens(f.tokens,e)))}}return n}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{const o={...n};if(o.async=this.defaults.async||o.async||!1,n.extensions&&(n.extensions.forEach(l=>{if(!l.name)throw new Error("extension name required");if("renderer"in l){const d=e.renderers[l.name];d?e.renderers[l.name]=function(...f){let g=l.renderer.apply(this,f);return g===!1&&(g=d.apply(this,f)),g}:e.renderers[l.name]=l.renderer}if("tokenizer"in l){if(!l.level||l.level!=="block"&&l.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const d=e[l.level];d?d.unshift(l.tokenizer):e[l.level]=[l.tokenizer],l.start&&(l.level==="block"?e.startBlock?e.startBlock.push(l.start):e.startBlock=[l.start]:l.level==="inline"&&(e.startInline?e.startInline.push(l.start):e.startInline=[l.start]))}"childTokens"in l&&l.childTokens&&(e.childTokens[l.name]=l.childTokens)}),o.extensions=e),n.renderer){const l=this.defaults.renderer||new _Renderer(this.defaults);for(const d in n.renderer){if(!(d in l))throw new Error(`renderer '${d}' does not exist`);if(["options","parser"].includes(d))continue;const f=d,g=n.renderer[f],b=l[f];l[f]=(..._)=>{let S=g.apply(l,_);return S===!1&&(S=b.apply(l,_)),S||""}}o.renderer=l}if(n.tokenizer){const l=this.defaults.tokenizer||new _Tokenizer(this.defaults);for(const d in n.tokenizer){if(!(d in l))throw new Error(`tokenizer '${d}' does not exist`);if(["options","rules","lexer"].includes(d))continue;const f=d,g=n.tokenizer[f],b=l[f];l[f]=(..._)=>{let S=g.apply(l,_);return S===!1&&(S=b.apply(l,_)),S}}o.tokenizer=l}if(n.hooks){const l=this.defaults.hooks||new _Hooks;for(const d in n.hooks){if(!(d in l))throw new Error(`hook '${d}' does not exist`);if(["options","block"].includes(d))continue;const f=d,g=n.hooks[f],b=l[f];_Hooks.passThroughHooks.has(d)?l[f]=_=>{if(this.defaults.async)return Promise.resolve(g.call(l,_)).then(R=>b.call(l,R));const S=g.call(l,_);return b.call(l,S)}:l[f]=(..._)=>{let S=g.apply(l,_);return S===!1&&(S=b.apply(l,_)),S}}o.hooks=l}if(n.walkTokens){const l=this.defaults.walkTokens,d=n.walkTokens;o.walkTokens=function(f){let g=[];return g.push(d.call(this,f)),l&&(g=g.concat(l.call(this,f))),g}}this.defaults={...this.defaults,...o}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return _Lexer.lex(t,e??this.defaults)}parser(t,e){return _Parser.parse(t,e??this.defaults)}parseMarkdown(t){return(n,o)=>{const l={...o},d={...this.defaults,...l},f=this.onError(!!d.silent,!!d.async);if(this.defaults.async===!0&&l.async===!1)return f(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof n>"u"||n===null)return f(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return f(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));d.hooks&&(d.hooks.options=d,d.hooks.block=t);const g=d.hooks?d.hooks.provideLexer():t?_Lexer.lex:_Lexer.lexInline,b=d.hooks?d.hooks.provideParser():t?_Parser.parse:_Parser.parseInline;if(d.async)return Promise.resolve(d.hooks?d.hooks.preprocess(n):n).then(_=>g(_,d)).then(_=>d.hooks?d.hooks.processAllTokens(_):_).then(_=>d.walkTokens?Promise.all(this.walkTokens(_,d.walkTokens)).then(()=>_):_).then(_=>b(_,d)).then(_=>d.hooks?d.hooks.postprocess(_):_).catch(f);try{d.hooks&&(n=d.hooks.preprocess(n));let _=g(n,d);d.hooks&&(_=d.hooks.processAllTokens(_)),d.walkTokens&&this.walkTokens(_,d.walkTokens);let S=b(_,d);return d.hooks&&(S=d.hooks.postprocess(S)),S}catch(_){return f(_)}}}onError(t,e){return n=>{if(n.message+=`
1052
1052
  Please report this to https://github.com/markedjs/marked.`,t){const o="<p>An error occurred:</p><pre>"+escape2(n.message+"",!0)+"</pre>";return e?Promise.resolve(o):o}if(e)return Promise.reject(n);throw n}}},markedInstance=new Marked;function marked(t,e){return markedInstance.parse(t,e)}marked.options=marked.setOptions=function(t){return markedInstance.setOptions(t),marked.defaults=markedInstance.defaults,changeDefaults(marked.defaults),marked},marked.getDefaults=_getDefaults,marked.defaults=_defaults,marked.use=function(...t){return markedInstance.use(...t),marked.defaults=markedInstance.defaults,changeDefaults(marked.defaults),marked},marked.walkTokens=function(t,e){return markedInstance.walkTokens(t,e)},marked.parseInline=markedInstance.parseInline,marked.Parser=_Parser,marked.parser=_Parser.parse,marked.Renderer=_Renderer,marked.TextRenderer=_TextRenderer,marked.Lexer=_Lexer,marked.lexer=_Lexer.lex,marked.Tokenizer=_Tokenizer,marked.Hooks=_Hooks,marked.parse=marked,marked.options,marked.setOptions,marked.use,marked.walkTokens,marked.parseInline,_Parser.parse,_Lexer.lex;/*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE */const{entries,setPrototypeOf,isFrozen,getPrototypeOf,getOwnPropertyDescriptor}=Object;let{freeze,seal,create}=Object,{apply:apply$1,construct}=typeof Reflect<"u"&&Reflect;freeze||(freeze=function(e){return e}),seal||(seal=function(e){return e}),apply$1||(apply$1=function(e,n,o){return e.apply(n,o)}),construct||(construct=function(e,n){return new e(...n)});const arrayForEach=unapply(Array.prototype.forEach),arrayLastIndexOf=unapply(Array.prototype.lastIndexOf),arrayPop=unapply(Array.prototype.pop),arrayPush=unapply(Array.prototype.push),arraySplice=unapply(Array.prototype.splice),stringToLowerCase=unapply(String.prototype.toLowerCase),stringToString=unapply(String.prototype.toString),stringMatch=unapply(String.prototype.match),stringReplace=unapply(String.prototype.replace),stringIndexOf=unapply(String.prototype.indexOf),stringTrim=unapply(String.prototype.trim),objectHasOwnProperty=unapply(Object.prototype.hasOwnProperty),regExpTest=unapply(RegExp.prototype.test),typeErrorCreate=unconstruct(TypeError);function unapply(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,o=new Array(n>1?n-1:0),l=1;l<n;l++)o[l-1]=arguments[l];return apply$1(t,e,o)}}function unconstruct(t){return function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return construct(t,n)}}function addToSet(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:stringToLowerCase;setPrototypeOf&&setPrototypeOf(t,null);let o=e.length;for(;o--;){let l=e[o];if(typeof l=="string"){const d=n(l);d!==l&&(isFrozen(e)||(e[o]=d),l=d)}t[l]=!0}return t}function cleanArray(t){for(let e=0;e<t.length;e++)objectHasOwnProperty(t,e)||(t[e]=null);return t}function clone(t){const e=create(null);for(const[n,o]of entries(t))objectHasOwnProperty(t,n)&&(Array.isArray(o)?e[n]=cleanArray(o):o&&typeof o=="object"&&o.constructor===Object?e[n]=clone(o):e[n]=o);return e}function lookupGetter(t,e){for(;t!==null;){const o=getOwnPropertyDescriptor(t,e);if(o){if(o.get)return unapply(o.get);if(typeof o.value=="function")return unapply(o.value)}t=getPrototypeOf(t)}function n(){return null}return n}const html$1=freeze(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),svg$1=freeze(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),svgFilters=freeze(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),svgDisallowed=freeze(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),mathMl$1=freeze(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),mathMlDisallowed=freeze(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),text$1=freeze(["#text"]),html=freeze(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),svg=freeze(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),mathMl=freeze(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),xml=freeze(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),MUSTACHE_EXPR=seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm),ERB_EXPR=seal(/<%[\w\W]*|[\w\W]*%>/gm),TMPLIT_EXPR=seal(/\$\{[\w\W]*/gm),DATA_ATTR=seal(/^data-[\-\w.\u00B7-\uFFFF]+$/),ARIA_ATTR=seal(/^aria-[\-\w]+$/),IS_ALLOWED_URI=seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),IS_SCRIPT_OR_DATA=seal(/^(?:\w+script|data):/i),ATTR_WHITESPACE=seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),DOCTYPE_NAME=seal(/^html$/i),CUSTOM_ELEMENT=seal(/^[a-z][.\w]*(-[.\w]+)+$/i);var EXPRESSIONS=Object.freeze({__proto__:null,ARIA_ATTR,ATTR_WHITESPACE,CUSTOM_ELEMENT,DATA_ATTR,DOCTYPE_NAME,ERB_EXPR,IS_ALLOWED_URI,IS_SCRIPT_OR_DATA,MUSTACHE_EXPR,TMPLIT_EXPR});const NODE_TYPE={element:1,text:3,progressingInstruction:7,comment:8,document:9},getGlobal=function t(){return typeof window>"u"?null:window},_createTrustedTypesPolicy=function t(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let o=null;const l="data-tt-policy-suffix";n&&n.hasAttribute(l)&&(o=n.getAttribute(l));const d="dompurify"+(o?"#"+o:"");try{return e.createPolicy(d,{createHTML(f){return f},createScriptURL(f){return f}})}catch{return console.warn("TrustedTypes policy "+d+" could not be created."),null}},_createHooksMap=function t(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function createDOMPurify(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:getGlobal();const e=Wt=>createDOMPurify(Wt);if(e.version="3.2.6",e.removed=[],!t||!t.document||t.document.nodeType!==NODE_TYPE.document||!t.Element)return e.isSupported=!1,e;let{document:n}=t;const o=n,l=o.currentScript,{DocumentFragment:d,HTMLTemplateElement:f,Node:g,Element:b,NodeFilter:_,NamedNodeMap:S=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:R,DOMParser:C,trustedTypes:E}=t,A=b.prototype,I=lookupGetter(A,"cloneNode"),M=lookupGetter(A,"remove"),j=lookupGetter(A,"nextSibling"),q=lookupGetter(A,"childNodes"),z=lookupGetter(A,"parentNode");if(typeof f=="function"){const Wt=n.createElement("template");Wt.content&&Wt.content.ownerDocument&&(n=Wt.content.ownerDocument)}let Q,F="";const{implementation:V,createNodeIterator:te,createDocumentFragment:ne,getElementsByTagName:se}=n,{importNode:ge}=o;let oe=_createHooksMap();e.isSupported=typeof entries=="function"&&typeof z=="function"&&V&&V.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:Ae,ERB_EXPR:je,TMPLIT_EXPR:Ne,DATA_ATTR:Oe,ARIA_ATTR:Fe,IS_SCRIPT_OR_DATA:ze,ATTR_WHITESPACE:$e,CUSTOM_ELEMENT:Be}=EXPRESSIONS;let{IS_ALLOWED_URI:qe}=EXPRESSIONS,Ge=null;const He=addToSet({},[...html$1,...svg$1,...svgFilters,...mathMl$1,...text$1]);let Ze=null;const tt=addToSet({},[...html,...svg,...mathMl,...xml]);let Ye=Object.seal(create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),rt=null,Xe=null,it=!0,et=!0,st=!1,ot=!0,Ue=!1,Ct=!0,Je=!1,pt=!1,Mt=!1,qt=!1,Ht=!1,Ft=!1,Ke=!0,at=!1;const Qe="user-content-";let ct=!0,ft=!1,dt={},yt=null;const zt=addToSet({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Yt=null;const or=addToSet({},["audio","video","img","source","image","track"]);let dr=null;const mt=addToSet({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Sr="http://www.w3.org/1998/Math/MathML",Rt="http://www.w3.org/2000/svg",Zt="http://www.w3.org/1999/xhtml";let Kt=Zt,nr=!1,ur=null;const Nr=addToSet({},[Sr,Rt,Zt],stringToString);let Tr=addToSet({},["mi","mo","mn","ms","mtext"]),gr=addToSet({},["annotation-xml"]);const xr=addToSet({},["title","style","font","a","script"]);let er=null;const Mr=["application/xhtml+xml","text/html"],Xt="text/html";let mr=null,Ir=null;const hn=n.createElement("form"),Dr=function(nt){return nt instanceof RegExp||nt instanceof Function},wr=function(){let nt=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Ir&&Ir===nt)){if((!nt||typeof nt!="object")&&(nt={}),nt=clone(nt),er=Mr.indexOf(nt.PARSER_MEDIA_TYPE)===-1?Xt:nt.PARSER_MEDIA_TYPE,mr=er==="application/xhtml+xml"?stringToString:stringToLowerCase,Ge=objectHasOwnProperty(nt,"ALLOWED_TAGS")?addToSet({},nt.ALLOWED_TAGS,mr):He,Ze=objectHasOwnProperty(nt,"ALLOWED_ATTR")?addToSet({},nt.ALLOWED_ATTR,mr):tt,ur=objectHasOwnProperty(nt,"ALLOWED_NAMESPACES")?addToSet({},nt.ALLOWED_NAMESPACES,stringToString):Nr,dr=objectHasOwnProperty(nt,"ADD_URI_SAFE_ATTR")?addToSet(clone(mt),nt.ADD_URI_SAFE_ATTR,mr):mt,Yt=objectHasOwnProperty(nt,"ADD_DATA_URI_TAGS")?addToSet(clone(or),nt.ADD_DATA_URI_TAGS,mr):or,yt=objectHasOwnProperty(nt,"FORBID_CONTENTS")?addToSet({},nt.FORBID_CONTENTS,mr):zt,rt=objectHasOwnProperty(nt,"FORBID_TAGS")?addToSet({},nt.FORBID_TAGS,mr):clone({}),Xe=objectHasOwnProperty(nt,"FORBID_ATTR")?addToSet({},nt.FORBID_ATTR,mr):clone({}),dt=objectHasOwnProperty(nt,"USE_PROFILES")?nt.USE_PROFILES:!1,it=nt.ALLOW_ARIA_ATTR!==!1,et=nt.ALLOW_DATA_ATTR!==!1,st=nt.ALLOW_UNKNOWN_PROTOCOLS||!1,ot=nt.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Ue=nt.SAFE_FOR_TEMPLATES||!1,Ct=nt.SAFE_FOR_XML!==!1,Je=nt.WHOLE_DOCUMENT||!1,qt=nt.RETURN_DOM||!1,Ht=nt.RETURN_DOM_FRAGMENT||!1,Ft=nt.RETURN_TRUSTED_TYPE||!1,Mt=nt.FORCE_BODY||!1,Ke=nt.SANITIZE_DOM!==!1,at=nt.SANITIZE_NAMED_PROPS||!1,ct=nt.KEEP_CONTENT!==!1,ft=nt.IN_PLACE||!1,qe=nt.ALLOWED_URI_REGEXP||IS_ALLOWED_URI,Kt=nt.NAMESPACE||Zt,Tr=nt.MATHML_TEXT_INTEGRATION_POINTS||Tr,gr=nt.HTML_INTEGRATION_POINTS||gr,Ye=nt.CUSTOM_ELEMENT_HANDLING||{},nt.CUSTOM_ELEMENT_HANDLING&&Dr(nt.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ye.tagNameCheck=nt.CUSTOM_ELEMENT_HANDLING.tagNameCheck),nt.CUSTOM_ELEMENT_HANDLING&&Dr(nt.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ye.attributeNameCheck=nt.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),nt.CUSTOM_ELEMENT_HANDLING&&typeof nt.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Ye.allowCustomizedBuiltInElements=nt.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Ue&&(et=!1),Ht&&(qt=!0),dt&&(Ge=addToSet({},text$1),Ze=[],dt.html===!0&&(addToSet(Ge,html$1),addToSet(Ze,html)),dt.svg===!0&&(addToSet(Ge,svg$1),addToSet(Ze,svg),addToSet(Ze,xml)),dt.svgFilters===!0&&(addToSet(Ge,svgFilters),addToSet(Ze,svg),addToSet(Ze,xml)),dt.mathMl===!0&&(addToSet(Ge,mathMl$1),addToSet(Ze,mathMl),addToSet(Ze,xml))),nt.ADD_TAGS&&(Ge===He&&(Ge=clone(Ge)),addToSet(Ge,nt.ADD_TAGS,mr)),nt.ADD_ATTR&&(Ze===tt&&(Ze=clone(Ze)),addToSet(Ze,nt.ADD_ATTR,mr)),nt.ADD_URI_SAFE_ATTR&&addToSet(dr,nt.ADD_URI_SAFE_ATTR,mr),nt.FORBID_CONTENTS&&(yt===zt&&(yt=clone(yt)),addToSet(yt,nt.FORBID_CONTENTS,mr)),ct&&(Ge["#text"]=!0),Je&&addToSet(Ge,["html","head","body"]),Ge.table&&(addToSet(Ge,["tbody"]),delete rt.tbody),nt.TRUSTED_TYPES_POLICY){if(typeof nt.TRUSTED_TYPES_POLICY.createHTML!="function")throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof nt.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');Q=nt.TRUSTED_TYPES_POLICY,F=Q.createHTML("")}else Q===void 0&&(Q=_createTrustedTypesPolicy(E,l)),Q!==null&&typeof F=="string"&&(F=Q.createHTML(""));freeze&&freeze(nt),Ir=nt}},nn=addToSet({},[...svg$1,...svgFilters,...svgDisallowed]),Or=addToSet({},[...mathMl$1,...mathMlDisallowed]),Br=function(nt){let It=z(nt);(!It||!It.tagName)&&(It={namespaceURI:Kt,tagName:"template"});const Ut=stringToLowerCase(nt.tagName),cr=stringToLowerCase(It.tagName);return ur[nt.namespaceURI]?nt.namespaceURI===Rt?It.namespaceURI===Zt?Ut==="svg":It.namespaceURI===Sr?Ut==="svg"&&(cr==="annotation-xml"||Tr[cr]):!!nn[Ut]:nt.namespaceURI===Sr?It.namespaceURI===Zt?Ut==="math":It.namespaceURI===Rt?Ut==="math"&&gr[cr]:!!Or[Ut]:nt.namespaceURI===Zt?It.namespaceURI===Rt&&!gr[cr]||It.namespaceURI===Sr&&!Tr[cr]?!1:!Or[Ut]&&(xr[Ut]||!nn[Ut]):!!(er==="application/xhtml+xml"&&ur[nt.namespaceURI]):!1},Rr=function(nt){arrayPush(e.removed,{element:nt});try{z(nt).removeChild(nt)}catch{M(nt)}},jr=function(nt,It){try{arrayPush(e.removed,{attribute:It.getAttributeNode(nt),from:It})}catch{arrayPush(e.removed,{attribute:null,from:It})}if(It.removeAttribute(nt),nt==="is")if(qt||Ht)try{Rr(It)}catch{}else try{It.setAttribute(nt,"")}catch{}},Yr=function(nt){let It=null,Ut=null;if(Mt)nt="<remove></remove>"+nt;else{const pr=stringMatch(nt,/^[\r\n\t ]+/);Ut=pr&&pr[0]}er==="application/xhtml+xml"&&Kt===Zt&&(nt='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+nt+"</body></html>");const cr=Q?Q.createHTML(nt):nt;if(Kt===Zt)try{It=new C().parseFromString(cr,er)}catch{}if(!It||!It.documentElement){It=V.createDocument(Kt,"template",null);try{It.documentElement.innerHTML=nr?F:cr}catch{}}const vr=It.body||It.documentElement;return nt&&Ut&&vr.insertBefore(n.createTextNode(Ut),vr.childNodes[0]||null),Kt===Zt?se.call(It,Je?"html":"body")[0]:Je?It.documentElement:vr},Zr=function(nt){return te.call(nt.ownerDocument||nt,nt,_.SHOW_ELEMENT|_.SHOW_COMMENT|_.SHOW_TEXT|_.SHOW_PROCESSING_INSTRUCTION|_.SHOW_CDATA_SECTION,null)},Hr=function(nt){return nt instanceof R&&(typeof nt.nodeName!="string"||typeof nt.textContent!="string"||typeof nt.removeChild!="function"||!(nt.attributes instanceof S)||typeof nt.removeAttribute!="function"||typeof nt.setAttribute!="function"||typeof nt.namespaceURI!="string"||typeof nt.insertBefore!="function"||typeof nt.hasChildNodes!="function")},Xr=function(nt){return typeof g=="function"&&nt instanceof g};function Ar(Wt,nt,It){arrayForEach(Wt,Ut=>{Ut.call(e,nt,It,Ir)})}const an=function(nt){let It=null;if(Ar(oe.beforeSanitizeElements,nt,null),Hr(nt))return Rr(nt),!0;const Ut=mr(nt.nodeName);if(Ar(oe.uponSanitizeElement,nt,{tagName:Ut,allowedTags:Ge}),Ct&&nt.hasChildNodes()&&!Xr(nt.firstElementChild)&&regExpTest(/<[/\w!]/g,nt.innerHTML)&&regExpTest(/<[/\w!]/g,nt.textContent)||nt.nodeType===NODE_TYPE.progressingInstruction||Ct&&nt.nodeType===NODE_TYPE.comment&&regExpTest(/<[/\w]/g,nt.data))return Rr(nt),!0;if(!Ge[Ut]||rt[Ut]){if(!rt[Ut]&&on(Ut)&&(Ye.tagNameCheck instanceof RegExp&&regExpTest(Ye.tagNameCheck,Ut)||Ye.tagNameCheck instanceof Function&&Ye.tagNameCheck(Ut)))return!1;if(ct&&!yt[Ut]){const cr=z(nt)||nt.parentNode,vr=q(nt)||nt.childNodes;if(vr&&cr){const pr=vr.length;for(let _r=pr-1;_r>=0;--_r){const Pr=I(vr[_r],!0);Pr.__removalCount=(nt.__removalCount||0)+1,cr.insertBefore(Pr,j(nt))}}}return Rr(nt),!0}return nt instanceof b&&!Br(nt)||(Ut==="noscript"||Ut==="noembed"||Ut==="noframes")&&regExpTest(/<\/no(script|embed|frames)/i,nt.innerHTML)?(Rr(nt),!0):(Ue&&nt.nodeType===NODE_TYPE.text&&(It=nt.textContent,arrayForEach([Ae,je,Ne],cr=>{It=stringReplace(It,cr," ")}),nt.textContent!==It&&(arrayPush(e.removed,{element:nt.cloneNode()}),nt.textContent=It)),Ar(oe.afterSanitizeElements,nt,null),!1)},sn=function(nt,It,Ut){if(Ke&&(It==="id"||It==="name")&&(Ut in n||Ut in hn))return!1;if(!(et&&!Xe[It]&&regExpTest(Oe,It))){if(!(it&&regExpTest(Fe,It))){if(!Ze[It]||Xe[It]){if(!(on(nt)&&(Ye.tagNameCheck instanceof RegExp&&regExpTest(Ye.tagNameCheck,nt)||Ye.tagNameCheck instanceof Function&&Ye.tagNameCheck(nt))&&(Ye.attributeNameCheck instanceof RegExp&&regExpTest(Ye.attributeNameCheck,It)||Ye.attributeNameCheck instanceof Function&&Ye.attributeNameCheck(It))||It==="is"&&Ye.allowCustomizedBuiltInElements&&(Ye.tagNameCheck instanceof RegExp&&regExpTest(Ye.tagNameCheck,Ut)||Ye.tagNameCheck instanceof Function&&Ye.tagNameCheck(Ut))))return!1}else if(!dr[It]){if(!regExpTest(qe,stringReplace(Ut,$e,""))){if(!((It==="src"||It==="xlink:href"||It==="href")&&nt!=="script"&&stringIndexOf(Ut,"data:")===0&&Yt[nt])){if(!(st&&!regExpTest(ze,stringReplace(Ut,$e,"")))){if(Ut)return!1}}}}}}return!0},on=function(nt){return nt!=="annotation-xml"&&stringMatch(nt,Be)},Jr=function(nt){Ar(oe.beforeSanitizeAttributes,nt,null);const{attributes:It}=nt;if(!It||Hr(nt))return;const Ut={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Ze,forceKeepAttr:void 0};let cr=It.length;for(;cr--;){const vr=It[cr],{name:pr,namespaceURI:_r,value:Pr}=vr,Vr=mr(pr),Qr=Pr;let Vt=pr==="value"?Qr:stringTrim(Qr);if(Ut.attrName=Vr,Ut.attrValue=Vt,Ut.keepAttr=!0,Ut.forceKeepAttr=void 0,Ar(oe.uponSanitizeAttribute,nt,Ut),Vt=Ut.attrValue,at&&(Vr==="id"||Vr==="name")&&(jr(pr,nt),Vt=Qe+Vt),Ct&&regExpTest(/((--!?|])>)|<\/(style|title)/i,Vt)){jr(pr,nt);continue}if(Ut.forceKeepAttr)continue;if(!Ut.keepAttr){jr(pr,nt);continue}if(!ot&&regExpTest(/\/>/i,Vt)){jr(pr,nt);continue}Ue&&arrayForEach([Ae,je,Ne],Cr=>{Vt=stringReplace(Vt,Cr," ")});const Lr=mr(nt.nodeName);if(!sn(Lr,Vr,Vt)){jr(pr,nt);continue}if(Q&&typeof E=="object"&&typeof E.getAttributeType=="function"&&!_r)switch(E.getAttributeType(Lr,Vr)){case"TrustedHTML":{Vt=Q.createHTML(Vt);break}case"TrustedScriptURL":{Vt=Q.createScriptURL(Vt);break}}if(Vt!==Qr)try{_r?nt.setAttributeNS(_r,pr,Vt):nt.setAttribute(pr,Vt),Hr(nt)?Rr(nt):arrayPop(e.removed)}catch{jr(pr,nt)}}Ar(oe.afterSanitizeAttributes,nt,null)},un=function Wt(nt){let It=null;const Ut=Zr(nt);for(Ar(oe.beforeSanitizeShadowDOM,nt,null);It=Ut.nextNode();)Ar(oe.uponSanitizeShadowNode,It,null),an(It),Jr(It),It.content instanceof d&&Wt(It.content);Ar(oe.afterSanitizeShadowDOM,nt,null)};return e.sanitize=function(Wt){let nt=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},It=null,Ut=null,cr=null,vr=null;if(nr=!Wt,nr&&(Wt="<!-->"),typeof Wt!="string"&&!Xr(Wt))if(typeof Wt.toString=="function"){if(Wt=Wt.toString(),typeof Wt!="string")throw typeErrorCreate("dirty is not a string, aborting")}else throw typeErrorCreate("toString is not a function");if(!e.isSupported)return Wt;if(pt||wr(nt),e.removed=[],typeof Wt=="string"&&(ft=!1),ft){if(Wt.nodeName){const Pr=mr(Wt.nodeName);if(!Ge[Pr]||rt[Pr])throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place")}}else if(Wt instanceof g)It=Yr("<!---->"),Ut=It.ownerDocument.importNode(Wt,!0),Ut.nodeType===NODE_TYPE.element&&Ut.nodeName==="BODY"||Ut.nodeName==="HTML"?It=Ut:It.appendChild(Ut);else{if(!qt&&!Ue&&!Je&&Wt.indexOf("<")===-1)return Q&&Ft?Q.createHTML(Wt):Wt;if(It=Yr(Wt),!It)return qt?null:Ft?F:""}It&&Mt&&Rr(It.firstChild);const pr=Zr(ft?Wt:It);for(;cr=pr.nextNode();)an(cr),Jr(cr),cr.content instanceof d&&un(cr.content);if(ft)return Wt;if(qt){if(Ht)for(vr=ne.call(It.ownerDocument);It.firstChild;)vr.appendChild(It.firstChild);else vr=It;return(Ze.shadowroot||Ze.shadowrootmode)&&(vr=ge.call(o,vr,!0)),vr}let _r=Je?It.outerHTML:It.innerHTML;return Je&&Ge["!doctype"]&&It.ownerDocument&&It.ownerDocument.doctype&&It.ownerDocument.doctype.name&&regExpTest(DOCTYPE_NAME,It.ownerDocument.doctype.name)&&(_r="<!DOCTYPE "+It.ownerDocument.doctype.name+`>
1053
- `+_r),Ue&&arrayForEach([Ae,je,Ne],Pr=>{_r=stringReplace(_r,Pr," ")}),Q&&Ft?Q.createHTML(_r):_r},e.setConfig=function(){let Wt=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};wr(Wt),pt=!0},e.clearConfig=function(){Ir=null,pt=!1},e.isValidAttribute=function(Wt,nt,It){Ir||wr({});const Ut=mr(Wt),cr=mr(nt);return sn(Ut,cr,It)},e.addHook=function(Wt,nt){typeof nt=="function"&&arrayPush(oe[Wt],nt)},e.removeHook=function(Wt,nt){if(nt!==void 0){const It=arrayLastIndexOf(oe[Wt],nt);return It===-1?void 0:arraySplice(oe[Wt],It,1)[0]}return arrayPop(oe[Wt])},e.removeHooks=function(Wt){oe[Wt]=[]},e.removeAllHooks=function(){oe=_createHooksMap()},e}var purify=createDOMPurify();function markdownToSafeHTML(t){var e=marked(t,{async:!1});return purify.sanitize(e,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","b","strong","i","em","u","s","sub","sup","mark","code","pre","blockquote","q","ul","ol","li","dl","dt","dd","p","div","span","br","hr","table","thead","tbody","tfoot","tr","th","td"]})}function SkeletonMessage({botStatus:t}){return jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx("div",{className:"h-8 w-8 mt-1 rounded-full bg-gray-300 animate-pulse flex-shrink-0"}),jsxRuntime.jsxs("div",{className:"flex flex-col max-w-[70%]",children:[jsxRuntime.jsxs("p",{className:"mb-1",children:["Assistant",jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground mt-1 ml-3",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]}),jsxRuntime.jsx("div",{className:"rounded-md p-3 break-words bg-white border rounded-tl-none",children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:t})]})})]})]})}function ChatMessages({messages:t,currentUserId:e,botStatus:n,isAssistantChat:o}){return jsxRuntime.jsxs("div",{children:[t.map(l=>{const d=l.fromPartnerID===e;return jsxRuntime.jsxs("div",{className:cn("flex items-start gap-2 mt-2 mb-2",d&&"flex-row-reverse"),children:[jsxRuntime.jsx(Avatar,{className:"h-8 w-8 mt-1",children:jsxRuntime.jsx(AvatarImage,{src:`https://api.dicebear.com/9.x/thumbs/svg?seed=${md5(l.senderName+l.fromPartnerID)}&flip=${d}`})}),jsxRuntime.jsxs("div",{className:"flex flex-col max-w-[70%]",children:[jsxRuntime.jsxs("p",{className:"mb-1",children:[l.senderName,jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground mt-1 ml-3",children:(()=>{const f=new Date(l.timestamp);return isToday(f)?f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):isYesterday(f)?`Yesterday, ${f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`:`${f.toLocaleDateString([],{month:"short",day:"numeric"})} ${f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`})()})]}),jsxRuntime.jsx("div",{className:cn("rounded-md p-3 break-words [&_li]:ml-6 [&_li]:list-disc [&_h1]:text-lg [&_h1]:font-bold [&_h1]:mt-4 [&_h2]:font-bold [&_h2]:mt-4 [&_h3]:mt-4 ",d?"bg-primary text-white rounded-tr-none":"bg-white border rounded-tl-none"),children:parser(markdownToSafeHTML(l.content))})]})]},l.id)}),n!==""&&jsxRuntime.jsx(SkeletonMessage,{botStatus:n}),t.length===0&&!o&&jsxRuntime.jsx("div",{className:"text-center text-muted-foreground py-8",children:"No messages yet"}),t.length===0&&n===""&&o&&jsxRuntime.jsxs("div",{className:"text-center py-8",children:[jsxRuntime.jsx("p",{children:"The Randmar Assistant is ready to help you. Ask anything about products, orders, carts, shipments and tracking numbers."}),jsxRuntime.jsx("p",{children:jsxRuntime.jsx("strong",{children:'Try it now, type "my open orders"!'})})]})]})}var SWITCH_NAME="Switch",[createSwitchContext,createSwitchScope]=createContextScope(SWITCH_NAME),[SwitchProvider,useSwitchContext]=createSwitchContext(SWITCH_NAME),Switch$1=React__namespace.forwardRef((t,e)=>{const{__scopeSwitch:n,name:o,checked:l,defaultChecked:d,required:f,disabled:g,value:b="on",onCheckedChange:_,form:S,...R}=t,[C,E]=React__namespace.useState(null),A=useComposedRefs(e,z=>E(z)),I=React__namespace.useRef(!1),M=C?S||!!C.closest("form"):!0,[j,q]=useControllableState({prop:l,defaultProp:d??!1,onChange:_,caller:SWITCH_NAME});return jsxRuntime.jsxs(SwitchProvider,{scope:n,checked:j,disabled:g,children:[jsxRuntime.jsx(Primitive.button,{type:"button",role:"switch","aria-checked":j,"aria-required":f,"data-state":getState$2(j),"data-disabled":g?"":void 0,disabled:g,value:b,...R,ref:A,onClick:composeEventHandlers(t.onClick,z=>{q(Q=>!Q),M&&(I.current=z.isPropagationStopped(),I.current||z.stopPropagation())})}),M&&jsxRuntime.jsx(SwitchBubbleInput,{control:C,bubbles:!I.current,name:o,value:b,checked:j,required:f,disabled:g,form:S,style:{transform:"translateX(-100%)"}})]})});Switch$1.displayName=SWITCH_NAME;var THUMB_NAME="SwitchThumb",SwitchThumb=React__namespace.forwardRef((t,e)=>{const{__scopeSwitch:n,...o}=t,l=useSwitchContext(THUMB_NAME,n);return jsxRuntime.jsx(Primitive.span,{"data-state":getState$2(l.checked),"data-disabled":l.disabled?"":void 0,...o,ref:e})});SwitchThumb.displayName=THUMB_NAME;var BUBBLE_INPUT_NAME$2="SwitchBubbleInput",SwitchBubbleInput=React__namespace.forwardRef(({__scopeSwitch:t,control:e,checked:n,bubbles:o=!0,...l},d)=>{const f=React__namespace.useRef(null),g=useComposedRefs(f,d),b=usePrevious(n),_=useSize(e);return React__namespace.useEffect(()=>{const S=f.current;if(!S)return;const R=window.HTMLInputElement.prototype,E=Object.getOwnPropertyDescriptor(R,"checked").set;if(b!==n&&E){const A=new Event("click",{bubbles:o});E.call(S,n),S.dispatchEvent(A)}},[b,n,o]),jsxRuntime.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...l,tabIndex:-1,ref:g,style:{...l.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});SwitchBubbleInput.displayName=BUBBLE_INPUT_NAME$2;function getState$2(t){return t?"checked":"unchecked"}var Root$1=Switch$1,Thumb=SwitchThumb;const Switch=React__namespace.forwardRef(({className:t,...e},n)=>jsxRuntime.jsx(Root$1,{className:cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...e,ref:n,children:jsxRuntime.jsx(Thumb,{className:cn("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Switch.displayName=Root$1.displayName;const DebugMessageDisplay=({debugMessages:t})=>{const[e,n]=React.useState({}),o=l=>{n(d=>({...d,[l]:!d[l]}))};return jsxRuntime.jsx("div",{children:t.map((l,d)=>{if(typeof l=="string")return jsxRuntime.jsx("p",{className:"text-slate-600",children:l},d);{const f=e[d];return jsxRuntime.jsxs("div",{className:"cursor-pointer",onClick:()=>o(d),children:[jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("p",{className:"text-slate-600 mr-2",children:l[0]}),jsxRuntime.jsx("span",{className:"text-slate-500 text-xs",children:f?"▲":"▼"})]}),f&&jsxRuntime.jsx("p",{className:"text-slate-400 pl-4",children:l[1]})]},d)}})})},ASSISTANT_ID="RandmarAIChatAssistant",sortChats=(t,e)=>t.unread>0&&e.unread===0?-1:e.unread>0&&t.unread===0?1:t.name.localeCompare(e.name),ChatLayout=React.forwardRef(({userId:t,userName:e,inputRef:n,assistantOnly:o,className:l,initialPrompt:d},f)=>{const{data:g,refetch:b}=useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsQuery({routeApplicationId:t},{skip:o===!0}),[_]=usePostV4PartnerByApplicationIdAccountDebugFeedbackMutation(),[S,{isLoading:R}]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[C,E]=React.useState(!1),A=React.useRef(null),I=React.useRef(!1),[M]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[j]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdReadMutation(),[q]=useLazyGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdMessagesQuery(),{handleSubmitToBot:z,botMessages:Q,clearBotMessages:F,botReady:V,debugMessages:te,botStatus:ne,reset:se}=useAIAssistant({userId:t,smartAndSlow:C});React.useEffect(()=>{const Rt={partner1:t,partner2:ASSISTANT_ID,name:"Randmar Assistant",unread:0,pending:!1,messages:[],conversationID:-1};if(o===!0){Ge([Rt]);return}if(!g)return;(async()=>{const Kt=g.map(async ur=>{var Tr,gr,xr;const Nr=await q({routeApplicationId:t,conversationId:ur.ConversationId});return{partner1:ur.Participant1,partner2:ur.Participant2,name:((Tr=ur.Participant)==null?void 0:Tr.PublicName)??"missing public name",unread:((gr=Nr.data)==null?void 0:gr.filter(er=>!er.Read&&er.SenderId!=t).length)??0,pending:ur.Status!=="Approved",messages:((xr=Nr.data)==null?void 0:xr.map(er=>({id:"history"+er.MessageId,fromPartnerID:er.SenderId,toPartnerID:er.SenderId==ur.Participant1?ur.Participant2:ur.Participant1,senderName:er.SenderName??"missing name",timestamp:new Date(er.SentDate+"Z").getTime(),content:er.Content??"no content"})))??[],conversationID:ur.ConversationId}}),nr=await Promise.all(Kt);nr.sort(sortChats),Ge([Rt,...nr]),setTimeout(()=>{var ur;return(ur=Ue.current)==null?void 0:ur.focus()},50)})()},[g,o,t]);const[ge,oe]=React.useState("approved"),[Ae,je]=React.useState([t,ASSISTANT_ID]),[Ne,Oe]=React.useState(""),[Fe,ze]=React.useState(null),[$e,Be]=React.useState(null),[qe,Ge]=React.useState([]),[He,Ze]=React.useState(""),[tt,Ye]=React.useState(null),rt=React.useRef(null),Xe=React.useRef(null),[it,et]=React.useState(null),[st,ot]=React.useState([]),Ue=n||Xe,Ct=React.useRef(null),{toast:Je}=useToast(),pt=()=>qe.find(Rt=>Rt.partner1===(Ae==null?void 0:Ae[0])&&Rt.partner2===(Ae==null?void 0:Ae[1])),Mt=()=>(Ae==null?void 0:Ae[0])===ASSISTANT_ID||(Ae==null?void 0:Ae[1])===ASSISTANT_ID;function qt(){const Rt=pt();Rt&&(Mt()||j({routeApplicationId:t,conversationId:Rt.conversationID}))}React.useEffect(()=>{d&&V&&(I.current||Mt()&&(I.current=!0,Ke(d)))},[d,V,Ae,I]),React.useEffect(()=>{Fe&&Ae&&(Ke(Fe),ze(null))},[Fe,Ae]);const Ht=React.useMemo(()=>qe.filter(Rt=>{const Zt=Rt.name.toLowerCase().includes(He.toLowerCase());return ge==="approved"?Zt&&!Rt.pending:ge==="pending"?Zt&&Rt.pending:Zt}),[qe,He,ge]);React.useEffect(()=>{var Rt;it!==null&&(Je({title:"File attached",description:"Add your instruction before sending.",variant:"success"}),(Rt=Ue.current)==null||Rt.focus())},[it]),React.useEffect(()=>{Q.length!==0&&(Q.forEach(Rt=>{if(!Rt||Rt.isComponent)return;const Zt={id:Rt.timestamp.toString(),fromPartnerID:ASSISTANT_ID,toPartnerID:t,senderName:"Assistant",timestamp:Rt.timestamp.getTime(),content:Rt.content};Ft(Zt)}),F())},[Q]);function Ft(Rt){Ge(Zt=>Zt.map(Kt=>{let nr=Kt.partner1===Rt.fromPartnerID&&Kt.partner2===Rt.toPartnerID;return nr||(nr=Kt.partner1===Rt.toPartnerID&&Kt.partner2===Rt.fromPartnerID),!nr||Kt.messages.some(ur=>ur.id===Rt.id)?Kt:(Be([Kt.partner1,Kt.partner2]),{...Kt,unread:Kt.unread+1,messages:[...Kt.messages,Rt]})}).sort(sortChats))}React.useEffect(()=>{if(o===!0)return;const Rt=new HubConnectionBuilder().withUrl("https://api.randmar.io/hub",{accessTokenFactory:()=>localStorage.getItem("access_token"),headers:{"X-Impersonated-Id":t}}).configureLogging(LogLevel.Information).withAutomaticReconnect().withHubProtocol(new JsonHubProtocol).build();return Rt.on("ReceiveMessage",Ft),Rt.start().catch(Zt=>console.error("Error connecting to SignalR hub:",Zt)),Ye(Rt),()=>{Rt&&Rt.stop()}},[t,o]),React.useEffect(()=>{($e==null?void 0:$e[0])!==(Ae==null?void 0:Ae[0])||($e==null?void 0:$e[1])!==(Ae==null?void 0:Ae[1])||(qt(),Ge(Rt=>Rt.map(Zt=>Zt.partner1===(Ae==null?void 0:Ae[0])&&Zt.partner2===(Ae==null?void 0:Ae[1])?{...Zt,unread:0}:Zt)),setTimeout(()=>{var Rt;return(Rt=rt.current)==null?void 0:Rt.scrollIntoView({behavior:"smooth"})},50))},[$e,Ae]),React.useEffect(()=>{var Zt;if(!Ae)return;const Rt=pt();Rt&&((Zt=Ue.current)==null||Zt.focus(),Rt.unread>0&&(qt(),Ge(Kt=>Kt.map(nr=>nr.partner1===Ae[0]&&nr.partner2===Ae[1]?{...nr,unread:0}:nr))),setTimeout(()=>{var Kt;return(Kt=rt.current)==null?void 0:Kt.scrollIntoView({behavior:"smooth"})},50))},[qe,Ae]);const Ke=Rt=>{if(!Ae)return;const Zt={id:crypto.randomUUID(),senderName:e,fromPartnerID:t,toPartnerID:Ae[0]===t?Ae[1]:Ae[0],content:Rt+(it?` (${it==null?void 0:it.name} attached)`:""),timestamp:Date.now()};Ge(Kt=>Kt.map(nr=>nr.partner1===Ae[0]&&nr.partner2===Ae[1]?{...nr,messages:[...nr.messages,Zt]}:nr)),Be([Ae[0],Ae[1]]),Zt.toPartnerID==ASSISTANT_ID?(z(Zt.content,it??void 0),it&&ot(Kt=>[...Kt,it.name])):tt.invoke("NewMessage",Zt).catch(Kt=>console.error("Error sending message:",Kt)),Oe(""),et(null),Ct.current&&(Ct.current.value="")},at=(Rt,Zt)=>{if(!qe.length||o!==!0&&!tt||!V)return!1;const Kt=qe.find(nr=>nr.conversationID===Rt);return Kt?(Kt.pending&&setTimeout(()=>oe("pending"),300),je([Kt.partner1,Kt.partner2]),Zt&&ze(Zt),!0):!1};if(React.useImperativeHandle(f,()=>({setActiveChatAndSendMessage:at})),!V)return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("div",{className:"flex items-center justify-center p-8",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),jsxRuntime.jsx("p",{children:"Loading API functions..."})]})})});const Qe=Rt=>{var Kt;if(!Mt())return;const Zt=(Kt=Rt.clipboardData)==null?void 0:Kt.items;if(Zt){for(let nr=0;nr<Zt.length;nr++)if(Zt[nr].type.indexOf("image")!==-1){const ur=Zt[nr].getAsFile();if(ur){et(ur);return}}}},ct=()=>{!Ne.trim()||!Ae||o!==!0&&!tt||Ke(Ne)},ft=Rt=>{Rt.target.files&&Rt.target.files[0]?et(Rt.target.files[0]):et(null)},dt=()=>{var Rt;(Rt=Ct.current)==null||Rt.click()},yt=()=>{var Rt;et(null),Je({title:"File removed",description:"No file will be sent to the assistant.",variant:"secondary"}),(Rt=Ue.current)==null||Rt.focus()},zt=()=>{const Zt={messages:qe.find(Kt=>Kt.partner1===ASSISTANT_ID||Kt.partner2===ASSISTANT_ID),debug:te};_({applicationId:t,emailAddress:e,body:Zt})},Yt=async()=>{A.current&&(A.current.disabled=!0),await M({routeApplicationId:t,partnerId:"2"}),await b()},or=()=>{Ge(Rt=>Rt.map(Kt=>Kt.partner1!==ASSISTANT_ID&&Kt.partner2!==ASSISTANT_ID?Kt:{...Kt,messages:[]})),ot([]),se()},dr=()=>{Ae&&S({routeApplicationId:t,partnerId:Ae[0]==t?Ae[1]:Ae[0]}).then(()=>{oe("approved")})},mt=pt(),Sr=qe.filter(Rt=>Rt.pending).length;return jsxRuntime.jsxs("div",{className:cn("flex overflow-hidden",l),children:[o!==!0&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"w-[260px] p-4 pt-3 flex flex-col border-r",children:[jsxRuntime.jsx("div",{className:"p-4 font-semibold border-b",children:"Communications"}),qe.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"p-2",children:jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(Search,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),jsxRuntime.jsx(Input,{placeholder:"Search chats...",className:"pl-8 h-9",value:He,onChange:Rt=>Ze(Rt.target.value)})]})}),jsxRuntime.jsx(Tabs,{value:ge,onValueChange:oe,className:"w-full mb-1",children:jsxRuntime.jsxs(TabsList,{className:"grid grid-cols-6 h-9 mx-2",children:[jsxRuntime.jsx(TabsTrigger,{value:"approved",className:"text-xs col-span-3",children:"Approved"}),jsxRuntime.jsxs(TabsTrigger,{value:"pending",className:"text-xs col-span-3",children:["Pending ",Sr>0&&`(${Sr})`]})]})})]}),jsxRuntime.jsx("div",{className:"mt-1 mb-1",children:qe.findIndex(Rt=>Rt.partner1==="2"||Rt.partner2==="2")<0?jsxRuntime.jsx(Button,{className:"w-full",ref:A,onClick:()=>Yt(),children:"Chat with Randmar"},"b1"):jsxRuntime.jsx("a",{target:"_blank",href:`https://dashboard.randmar.io/${t}/ExploreManufacturers`,children:jsxRuntime.jsx(Button,{className:"w-full",children:"Explore manufacturers"},"b2")})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1",children:qe.length&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ChatList,{userId:t,chats:Ht.filter(Rt=>Rt.partner1!=ASSISTANT_ID&&Rt.partner2!=ASSISTANT_ID),activeChat:mt??null,onSelectChat:je,assistantChat:qe.find(Rt=>Rt.partner1==ASSISTANT_ID||Rt.partner2==ASSISTANT_ID)})})})]})}),jsxRuntime.jsx("div",{className:"flex-5 flex flex-col",children:Ae?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:Ae[0]==ASSISTANT_ID||Ae[1]==ASSISTANT_ID?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Avatar,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:jsxRuntime.jsx(Bot,{className:"text-primary fill-white min-h-full"})}),jsxRuntime.jsx("div",{className:"ml-3 font-medium",children:"Randmar Assistant"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 ml-auto",children:[jsxRuntime.jsx(Switch,{id:"smartSwitch",disabled:!!ne,checked:C,onCheckedChange:Rt=>{or(),setTimeout(()=>E(Rt),20)}}),jsxRuntime.jsx(Label$2,{htmlFor:"smartSwitch",children:"Think harder"})]}),jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"ml-1",onClick:()=>or(),children:jsxRuntime.jsx(MessageCircleX,{className:"h-5 w-5"})}),jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"ml-1",confirmationDialog:{title:"Report Issue",content:"This action will send a copy of your chat to Randmar. Send it?",onConfirm:()=>zt()},children:jsxRuntime.jsx(MessageSquareShare,{className:"h-5 w-5"})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Avatar,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:[jsxRuntime.jsx(AvatarImage,{src:`https://api.randmar.io/v4/Partner/${Ae[0]===t?Ae[1]:Ae[0]}/Account/Logo?height=72&width=72`,className:" object-contain "}),jsxRuntime.jsx(AvatarFallback,{children:jsxRuntime.jsx(Handshake,{className:"text-primary fill-white min-h-full"})})]}),jsxRuntime.jsx("div",{className:"ml-3 font-medium",children:mt==null?void 0:mt.name}),jsxRuntime.jsx("div",{className:"flex items-center space-x-2 ml-auto",children:jsxRuntime.jsx("a",{href:`https://dashboard.randmar.io/${t}/Partner/${Ae[0]===t?Ae[1]:Ae[0]}`,target:"_blank",children:jsxRuntime.jsx(Button,{children:"View Partner"})})})]})}),mt!=null&&mt.pending&&mt.partner1==t?jsxRuntime.jsx("p",{className:"mt-8 p-2 mx-auto",children:"This conversation is awaiting approval by the other party — please check back later."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:[jsxRuntime.jsx(ChatMessages,{messages:(mt==null?void 0:mt.messages)??[],currentUserId:t,isAssistantChat:Mt(),botStatus:Mt()?ne:""}),jsxRuntime.jsx("div",{ref:rt})]}),jsxRuntime.jsxs("div",{className:"p-4 border-t border-r flex",children:[(mt==null?void 0:mt.pending)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{disabled:R,onClick:()=>dr(),children:[jsxRuntime.jsx(Handshake,{}),"Accept Conversation Request"]}),jsxRuntime.jsxs(Button,{disabled:!0,className:"ml-2",children:[jsxRuntime.jsx(ThumbsDown,{}),"Block Partner"]})]}),jsxRuntime.jsx(Textarea,{ref:Ue,placeholder:"Type a message...",value:Ne,onPaste:Qe,onChange:Rt=>Oe(Rt.target.value),onKeyDown:Rt=>{Rt.key!=="Enter"||Rt.shiftKey||(Rt.preventDefault(),ct())},className:mt!=null&&mt.pending?"collapse":"flex-1 resize-none"}),jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(Button,{size:"icon",variant:"default",className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:!!ne||(mt==null?void 0:mt.pending),onClick:ct,children:jsxRuntime.jsx(Send,{className:"h-6 w-6"})}),Mt()&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Input,{type:"file",onChange:ft,className:"hidden",ref:Ct}),jsxRuntime.jsx(Button,{size:"icon",variant:"default",onClick:dt,className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:ne!==""||(mt==null?void 0:mt.pending)||!!it,children:jsxRuntime.jsx(Paperclip,{className:"h-5 w-5"})}),jsxRuntime.jsx(Button,{size:"icon",variant:"default",onClick:yt,className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:ne!==""||(mt==null?void 0:mt.pending)||!it,children:jsxRuntime.jsx(Trash,{className:"h-5 w-5"})})]})]})]})]})]}):jsxRuntime.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a chat to start messaging"})}),jsxRuntime.jsx("div",{"data-thin":Mt(),className:"w-[480px] flex flex-col border-l flex-4 data-[thin=true]:flex-2",children:Mt()?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:jsxRuntime.jsx("p",{className:"h-9 text-base/9",children:"Sources and System Info"})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsxs("div",{className:"space-y-2",children:[it?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsx(File,{})," ",it.name," (pending send...)"]})}):st.length?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("p",{children:"No files attached to this conversation yet."}),st.slice().reverse().map(Rt=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsx(File,{})," ",Rt]})}))]})}),jsxRuntime.jsx(ScrollArea,{className:"flex-4 border-t pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsx("div",{className:"space-y-2",children:jsxRuntime.jsx(DebugMessageDisplay,{debugMessages:te})})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:jsxRuntime.jsx("p",{className:"h-9 text-base/9",children:"Partner Overview"})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(PartnerRelationshipPage,{applicationId:t,partnerId:((Ae==null?void 0:Ae[0])===t?Ae[1]:Ae==null?void 0:Ae[0])??t,userEmail:e,shopifyHostName:void 0,isSuperAdmin:!1})})})]})})]})});function UnsavedChangesDialog({isOpen:t,onClose:e,onConfirm:n,title:o,description:l,confirmText:d="Confirm",cancelText:f="Cancel"}){return jsxRuntime.jsx(Dialog,{open:t,onOpenChange:e,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:o}),jsxRuntime.jsx(DialogDescription,{children:l})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:e,children:f}),jsxRuntime.jsx(Button,{onClick:n,children:d})]})]})})}function useRouterNavigationGuard(t){const[e,n]=React.useState(!1),o=reactRouterDom.useBlocker(React.useCallback(({currentLocation:g,nextLocation:b})=>{const _=g.pathname!==b.pathname||g.search!==b.search||g.hash!==b.hash;return t()&&_},[t]));React.useEffect(()=>{o.state==="blocked"&&n(!0)},[o]),React.useEffect(()=>{const g=b=>{if(t())return b.preventDefault(),"You have unsaved changes. Are you sure you want to leave?"};return window.addEventListener("beforeunload",g),()=>{window.removeEventListener("beforeunload",g)}},[t]);const l=React.useCallback(()=>{n(!1),o.state==="blocked"&&o.proceed()},[o]),d=React.useCallback(()=>{n(!1),o.state==="blocked"&&o.reset()},[o]),f=React.useCallback(()=>jsxRuntime.jsx(UnsavedChangesDialog,{isOpen:e,onClose:d,onConfirm:l,title:"Unsaved Changes",description:"You have unsaved changes. Are you sure you want to leave? Your changes will be lost.",confirmText:"Discard Changes",cancelText:"Stay on Page"}),[e,d,l]);return{showDialog:e,handleConfirm:l,handleCancel:d,NavigationGuardDialog:f}}var isCheckBoxInput=t=>t.type==="checkbox",isDateObject=t=>t instanceof Date,isNullOrUndefined=t=>t==null;const isObjectType=t=>typeof t=="object";var isObject=t=>!isNullOrUndefined(t)&&!Array.isArray(t)&&isObjectType(t)&&!isDateObject(t),getEventValue=t=>isObject(t)&&t.target?isCheckBoxInput(t.target)?t.target.checked:t.target.value:t,getNodeParentName=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,isNameInFieldArray=(t,e)=>t.has(getNodeParentName(e)),isPlainObject$1=t=>{const e=t.constructor&&t.constructor.prototype;return isObject(e)&&e.hasOwnProperty("isPrototypeOf")},isWeb=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function cloneObject(t){let e;const n=Array.isArray(t),o=typeof FileList<"u"?t instanceof FileList:!1;if(t instanceof Date)e=new Date(t);else if(t instanceof Set)e=new Set(t);else if(!(isWeb&&(t instanceof Blob||o))&&(n||isObject(t)))if(e=n?[]:{},!n&&!isPlainObject$1(t))e=t;else for(const l in t)t.hasOwnProperty(l)&&(e[l]=cloneObject(t[l]));else return t;return e}var compact=t=>Array.isArray(t)?t.filter(Boolean):[],isUndefined=t=>t===void 0,get=(t,e,n)=>{if(!e||!isObject(t))return n;const o=compact(e.split(/[,[\].]+?/)).reduce((l,d)=>isNullOrUndefined(l)?l:l[d],t);return isUndefined(o)||o===t?isUndefined(t[e])?n:t[e]:o},isBoolean=t=>typeof t=="boolean",isKey=t=>/^\w*$/.test(t),stringToPath=t=>compact(t.replace(/["|']|\]/g,"").split(/\.|\[/)),set=(t,e,n)=>{let o=-1;const l=isKey(e)?[e]:stringToPath(e),d=l.length,f=d-1;for(;++o<d;){const g=l[o];let b=n;if(o!==f){const _=t[g];b=isObject(_)||Array.isArray(_)?_:isNaN(+l[o+1])?{}:[]}if(g==="__proto__"||g==="constructor"||g==="prototype")return;t[g]=b,t=t[g]}};const EVENTS={BLUR:"blur",FOCUS_OUT:"focusout"},VALIDATION_MODE={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},INPUT_VALIDATION_RULES={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};React.createContext(null);var getProxyFormState=(t,e,n,o=!0)=>{const l={defaultValues:e._defaultValues};for(const d in t)Object.defineProperty(l,d,{get:()=>{const f=d;return e._proxyFormState[f]!==VALIDATION_MODE.all&&(e._proxyFormState[f]=!o||VALIDATION_MODE.all),t[f]}});return l};const useIsomorphicLayoutEffect$1=typeof window<"u"?React__namespace.useLayoutEffect:React__namespace.useEffect;var isString=t=>typeof t=="string",generateWatchOutput=(t,e,n,o,l)=>isString(t)?(o&&e.watch.add(t),get(n,t,l)):Array.isArray(t)?t.map(d=>(o&&e.watch.add(d),get(n,d))):(o&&(e.watchAll=!0),n),appendErrors=(t,e,n,o,l)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[o]:l||!0}}:{},convertToArrayPayload=t=>Array.isArray(t)?t:[t],createSubject=()=>{let t=[];return{get observers(){return t},next:l=>{for(const d of t)d.next&&d.next(l)},subscribe:l=>(t.push(l),{unsubscribe:()=>{t=t.filter(d=>d!==l)}}),unsubscribe:()=>{t=[]}}},isPrimitive=t=>isNullOrUndefined(t)||!isObjectType(t);function deepEqual$1(t,e){if(isPrimitive(t)||isPrimitive(e))return t===e;if(isDateObject(t)&&isDateObject(e))return t.getTime()===e.getTime();const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const l of n){const d=t[l];if(!o.includes(l))return!1;if(l!=="ref"){const f=e[l];if(isDateObject(d)&&isDateObject(f)||isObject(d)&&isObject(f)||Array.isArray(d)&&Array.isArray(f)?!deepEqual$1(d,f):d!==f)return!1}}return!0}var isEmptyObject$1=t=>isObject(t)&&!Object.keys(t).length,isFileInput=t=>t.type==="file",isFunction$3=t=>typeof t=="function",isHTMLElement=t=>{if(!isWeb)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},isMultipleSelect=t=>t.type==="select-multiple",isRadioInput=t=>t.type==="radio",isRadioOrCheckbox=t=>isRadioInput(t)||isCheckBoxInput(t),live=t=>isHTMLElement(t)&&t.isConnected;function baseGet(t,e){const n=e.slice(0,-1).length;let o=0;for(;o<n;)t=isUndefined(t)?o++:t[e[o++]];return t}function isEmptyArray(t){for(const e in t)if(t.hasOwnProperty(e)&&!isUndefined(t[e]))return!1;return!0}function unset(t,e){const n=Array.isArray(e)?e:isKey(e)?[e]:stringToPath(e),o=n.length===1?t:baseGet(t,n),l=n.length-1,d=n[l];return o&&delete o[d],l!==0&&(isObject(o)&&isEmptyObject$1(o)||Array.isArray(o)&&isEmptyArray(o))&&unset(t,n.slice(0,-1)),t}var objectHasFunction=t=>{for(const e in t)if(isFunction$3(t[e]))return!0;return!1};function markFieldsDirty(t,e={}){const n=Array.isArray(t);if(isObject(t)||n)for(const o in t)Array.isArray(t[o])||isObject(t[o])&&!objectHasFunction(t[o])?(e[o]=Array.isArray(t[o])?[]:{},markFieldsDirty(t[o],e[o])):isNullOrUndefined(t[o])||(e[o]=!0);return e}function getDirtyFieldsFromDefaultValues(t,e,n){const o=Array.isArray(t);if(isObject(t)||o)for(const l in t)Array.isArray(t[l])||isObject(t[l])&&!objectHasFunction(t[l])?isUndefined(e)||isPrimitive(n[l])?n[l]=Array.isArray(t[l])?markFieldsDirty(t[l],[]):{...markFieldsDirty(t[l])}:getDirtyFieldsFromDefaultValues(t[l],isNullOrUndefined(e)?{}:e[l],n[l]):n[l]=!deepEqual$1(t[l],e[l]);return n}var getDirtyFields=(t,e)=>getDirtyFieldsFromDefaultValues(t,e,markFieldsDirty(e));const defaultResult={value:!1,isValid:!1},validResult={value:!0,isValid:!0};var getCheckboxValue=t=>{if(Array.isArray(t)){if(t.length>1){const e=t.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:e,isValid:!!e.length}}return t[0].checked&&!t[0].disabled?t[0].attributes&&!isUndefined(t[0].attributes.value)?isUndefined(t[0].value)||t[0].value===""?validResult:{value:t[0].value,isValid:!0}:validResult:defaultResult}return defaultResult},getFieldValueAs=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:o})=>isUndefined(t)?t:e?t===""?NaN:t&&+t:n&&isString(t)?new Date(t):o?o(t):t;const defaultReturn={isValid:!1,value:null};var getRadioValue=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,defaultReturn):defaultReturn;function getFieldValue(t){const e=t.ref;return isFileInput(e)?e.files:isRadioInput(e)?getRadioValue(t.refs).value:isMultipleSelect(e)?[...e.selectedOptions].map(({value:n})=>n):isCheckBoxInput(e)?getCheckboxValue(t.refs).value:getFieldValueAs(isUndefined(e.value)?t.ref.value:e.value,t)}var getResolverOptions=(t,e,n,o)=>{const l={};for(const d of t){const f=get(e,d);f&&set(l,d,f._f)}return{criteriaMode:n,names:[...t],fields:l,shouldUseNativeValidation:o}},isRegex=t=>t instanceof RegExp,getRuleValue=t=>isUndefined(t)?t:isRegex(t)?t.source:isObject(t)?isRegex(t.value)?t.value.source:t.value:t,getValidationModes=t=>({isOnSubmit:!t||t===VALIDATION_MODE.onSubmit,isOnBlur:t===VALIDATION_MODE.onBlur,isOnChange:t===VALIDATION_MODE.onChange,isOnAll:t===VALIDATION_MODE.all,isOnTouch:t===VALIDATION_MODE.onTouched});const ASYNC_FUNCTION="AsyncFunction";var hasPromiseValidation=t=>!!t&&!!t.validate&&!!(isFunction$3(t.validate)&&t.validate.constructor.name===ASYNC_FUNCTION||isObject(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===ASYNC_FUNCTION)),hasValidation=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate),isWatched=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(o=>t.startsWith(o)&&/^\.\w+/.test(t.slice(o.length))));const iterateFieldsByAction=(t,e,n,o)=>{for(const l of n||Object.keys(t)){const d=get(t,l);if(d){const{_f:f,...g}=d;if(f){if(f.refs&&f.refs[0]&&e(f.refs[0],l)&&!o)return!0;if(f.ref&&e(f.ref,f.name)&&!o)return!0;if(iterateFieldsByAction(g,e))break}else if(isObject(g)&&iterateFieldsByAction(g,e))break}}};function schemaErrorLookup(t,e,n){const o=get(t,n);if(o||isKey(n))return{error:o,name:n};const l=n.split(".");for(;l.length;){const d=l.join("."),f=get(e,d),g=get(t,d);if(f&&!Array.isArray(f)&&n!==d)return{name:n};if(g&&g.type)return{name:d,error:g};if(g&&g.root&&g.root.type)return{name:`${d}.root`,error:g.root};l.pop()}return{name:n}}var shouldRenderFormState=(t,e,n,o)=>{n(t);const{name:l,...d}=t;return isEmptyObject$1(d)||Object.keys(d).length>=Object.keys(e).length||Object.keys(d).find(f=>e[f]===(!o||VALIDATION_MODE.all))},shouldSubscribeByName=(t,e,n)=>!t||!e||t===e||convertToArrayPayload(t).some(o=>o&&(n?o===e:o.startsWith(e)||e.startsWith(o))),skipValidation=(t,e,n,o,l)=>l.isOnAll?!1:!n&&l.isOnTouch?!(e||t):(n?o.isOnBlur:l.isOnBlur)?!t:(n?o.isOnChange:l.isOnChange)?t:!0,unsetEmptyArray=(t,e)=>!compact(get(t,e)).length&&unset(t,e),updateFieldArrayRootError=(t,e,n)=>{const o=convertToArrayPayload(get(t,n));return set(o,"root",e[n]),set(t,n,o),t},isMessage=t=>isString(t);function getValidateError(t,e,n="validate"){if(isMessage(t)||Array.isArray(t)&&t.every(isMessage)||isBoolean(t)&&!t)return{type:n,message:isMessage(t)?t:"",ref:e}}var getValueAndMessage=t=>isObject(t)&&!isRegex(t)?t:{value:t,message:""},validateField=async(t,e,n,o,l,d)=>{const{ref:f,refs:g,required:b,maxLength:_,minLength:S,min:R,max:C,pattern:E,validate:A,name:I,valueAsNumber:M,mount:j}=t._f,q=get(n,I);if(!j||e.has(I))return{};const z=g?g[0]:f,Q=Ae=>{l&&z.reportValidity&&(z.setCustomValidity(isBoolean(Ae)?"":Ae||""),z.reportValidity())},F={},V=isRadioInput(f),te=isCheckBoxInput(f),ne=V||te,se=(M||isFileInput(f))&&isUndefined(f.value)&&isUndefined(q)||isHTMLElement(f)&&f.value===""||q===""||Array.isArray(q)&&!q.length,ge=appendErrors.bind(null,I,o,F),oe=(Ae,je,Ne,Oe=INPUT_VALIDATION_RULES.maxLength,Fe=INPUT_VALIDATION_RULES.minLength)=>{const ze=Ae?je:Ne;F[I]={type:Ae?Oe:Fe,message:ze,ref:f,...ge(Ae?Oe:Fe,ze)}};if(d?!Array.isArray(q)||!q.length:b&&(!ne&&(se||isNullOrUndefined(q))||isBoolean(q)&&!q||te&&!getCheckboxValue(g).isValid||V&&!getRadioValue(g).isValid)){const{value:Ae,message:je}=isMessage(b)?{value:!!b,message:b}:getValueAndMessage(b);if(Ae&&(F[I]={type:INPUT_VALIDATION_RULES.required,message:je,ref:z,...ge(INPUT_VALIDATION_RULES.required,je)},!o))return Q(je),F}if(!se&&(!isNullOrUndefined(R)||!isNullOrUndefined(C))){let Ae,je;const Ne=getValueAndMessage(C),Oe=getValueAndMessage(R);if(!isNullOrUndefined(q)&&!isNaN(q)){const Fe=f.valueAsNumber||q&&+q;isNullOrUndefined(Ne.value)||(Ae=Fe>Ne.value),isNullOrUndefined(Oe.value)||(je=Fe<Oe.value)}else{const Fe=f.valueAsDate||new Date(q),ze=qe=>new Date(new Date().toDateString()+" "+qe),$e=f.type=="time",Be=f.type=="week";isString(Ne.value)&&q&&(Ae=$e?ze(q)>ze(Ne.value):Be?q>Ne.value:Fe>new Date(Ne.value)),isString(Oe.value)&&q&&(je=$e?ze(q)<ze(Oe.value):Be?q<Oe.value:Fe<new Date(Oe.value))}if((Ae||je)&&(oe(!!Ae,Ne.message,Oe.message,INPUT_VALIDATION_RULES.max,INPUT_VALIDATION_RULES.min),!o))return Q(F[I].message),F}if((_||S)&&!se&&(isString(q)||d&&Array.isArray(q))){const Ae=getValueAndMessage(_),je=getValueAndMessage(S),Ne=!isNullOrUndefined(Ae.value)&&q.length>+Ae.value,Oe=!isNullOrUndefined(je.value)&&q.length<+je.value;if((Ne||Oe)&&(oe(Ne,Ae.message,je.message),!o))return Q(F[I].message),F}if(E&&!se&&isString(q)){const{value:Ae,message:je}=getValueAndMessage(E);if(isRegex(Ae)&&!q.match(Ae)&&(F[I]={type:INPUT_VALIDATION_RULES.pattern,message:je,ref:f,...ge(INPUT_VALIDATION_RULES.pattern,je)},!o))return Q(je),F}if(A){if(isFunction$3(A)){const Ae=await A(q,n),je=getValidateError(Ae,z);if(je&&(F[I]={...je,...ge(INPUT_VALIDATION_RULES.validate,je.message)},!o))return Q(je.message),F}else if(isObject(A)){let Ae={};for(const je in A){if(!isEmptyObject$1(Ae)&&!o)break;const Ne=getValidateError(await A[je](q,n),z,je);Ne&&(Ae={...Ne,...ge(je,Ne.message)},Q(Ne.message),o&&(F[I]=Ae))}if(!isEmptyObject$1(Ae)&&(F[I]={ref:z,...Ae},!o))return F}}return Q(!0),F};const defaultOptions$1={mode:VALIDATION_MODE.onSubmit,reValidateMode:VALIDATION_MODE.onChange,shouldFocusError:!0};function createFormControl(t={}){let e={...defaultOptions$1,...t},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:isFunction$3(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1};const o={};let l=isObject(e.defaultValues)||isObject(e.values)?cloneObject(e.defaultValues||e.values)||{}:{},d=e.shouldUnregister?{}:cloneObject(l),f={action:!1,mount:!1,watch:!1},g={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},b,_=0;const S={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let R={...S};const C={array:createSubject(),state:createSubject()},E=e.criteriaMode===VALIDATION_MODE.all,A=Ke=>at=>{clearTimeout(_),_=setTimeout(Ke,at)},I=async Ke=>{if(!e.disabled&&(S.isValid||R.isValid||Ke)){const at=e.resolver?isEmptyObject$1((await te()).errors):await se(o,!0);at!==n.isValid&&C.state.next({isValid:at})}},M=(Ke,at)=>{!e.disabled&&(S.isValidating||S.validatingFields||R.isValidating||R.validatingFields)&&((Ke||Array.from(g.mount)).forEach(Qe=>{Qe&&(at?set(n.validatingFields,Qe,at):unset(n.validatingFields,Qe))}),C.state.next({validatingFields:n.validatingFields,isValidating:!isEmptyObject$1(n.validatingFields)}))},j=(Ke,at=[],Qe,ct,ft=!0,dt=!0)=>{if(ct&&Qe&&!e.disabled){if(f.action=!0,dt&&Array.isArray(get(o,Ke))){const yt=Qe(get(o,Ke),ct.argA,ct.argB);ft&&set(o,Ke,yt)}if(dt&&Array.isArray(get(n.errors,Ke))){const yt=Qe(get(n.errors,Ke),ct.argA,ct.argB);ft&&set(n.errors,Ke,yt),unsetEmptyArray(n.errors,Ke)}if((S.touchedFields||R.touchedFields)&&dt&&Array.isArray(get(n.touchedFields,Ke))){const yt=Qe(get(n.touchedFields,Ke),ct.argA,ct.argB);ft&&set(n.touchedFields,Ke,yt)}(S.dirtyFields||R.dirtyFields)&&(n.dirtyFields=getDirtyFields(l,d)),C.state.next({name:Ke,isDirty:oe(Ke,at),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else set(d,Ke,at)},q=(Ke,at)=>{set(n.errors,Ke,at),C.state.next({errors:n.errors})},z=Ke=>{n.errors=Ke,C.state.next({errors:n.errors,isValid:!1})},Q=(Ke,at,Qe,ct)=>{const ft=get(o,Ke);if(ft){const dt=get(d,Ke,isUndefined(Qe)?get(l,Ke):Qe);isUndefined(dt)||ct&&ct.defaultChecked||at?set(d,Ke,at?dt:getFieldValue(ft._f)):Ne(Ke,dt),f.mount&&I()}},F=(Ke,at,Qe,ct,ft)=>{let dt=!1,yt=!1;const zt={name:Ke};if(!e.disabled){if(!Qe||ct){(S.isDirty||R.isDirty)&&(yt=n.isDirty,n.isDirty=zt.isDirty=oe(),dt=yt!==zt.isDirty);const Yt=deepEqual$1(get(l,Ke),at);yt=!!get(n.dirtyFields,Ke),Yt?unset(n.dirtyFields,Ke):set(n.dirtyFields,Ke,!0),zt.dirtyFields=n.dirtyFields,dt=dt||(S.dirtyFields||R.dirtyFields)&&yt!==!Yt}if(Qe){const Yt=get(n.touchedFields,Ke);Yt||(set(n.touchedFields,Ke,Qe),zt.touchedFields=n.touchedFields,dt=dt||(S.touchedFields||R.touchedFields)&&Yt!==Qe)}dt&&ft&&C.state.next(zt)}return dt?zt:{}},V=(Ke,at,Qe,ct)=>{const ft=get(n.errors,Ke),dt=(S.isValid||R.isValid)&&isBoolean(at)&&n.isValid!==at;if(e.delayError&&Qe?(b=A(()=>q(Ke,Qe)),b(e.delayError)):(clearTimeout(_),b=null,Qe?set(n.errors,Ke,Qe):unset(n.errors,Ke)),(Qe?!deepEqual$1(ft,Qe):ft)||!isEmptyObject$1(ct)||dt){const yt={...ct,...dt&&isBoolean(at)?{isValid:at}:{},errors:n.errors,name:Ke};n={...n,...yt},C.state.next(yt)}},te=async Ke=>{M(Ke,!0);const at=await e.resolver(d,e.context,getResolverOptions(Ke||g.mount,o,e.criteriaMode,e.shouldUseNativeValidation));return M(Ke),at},ne=async Ke=>{const{errors:at}=await te(Ke);if(Ke)for(const Qe of Ke){const ct=get(at,Qe);ct?set(n.errors,Qe,ct):unset(n.errors,Qe)}else n.errors=at;return at},se=async(Ke,at,Qe={valid:!0})=>{for(const ct in Ke){const ft=Ke[ct];if(ft){const{_f:dt,...yt}=ft;if(dt){const zt=g.array.has(dt.name),Yt=ft._f&&hasPromiseValidation(ft._f);Yt&&S.validatingFields&&M([ct],!0);const or=await validateField(ft,g.disabled,d,E,e.shouldUseNativeValidation&&!at,zt);if(Yt&&S.validatingFields&&M([ct]),or[dt.name]&&(Qe.valid=!1,at))break;!at&&(get(or,dt.name)?zt?updateFieldArrayRootError(n.errors,or,dt.name):set(n.errors,dt.name,or[dt.name]):unset(n.errors,dt.name))}!isEmptyObject$1(yt)&&await se(yt,at,Qe)}}return Qe.valid},ge=()=>{for(const Ke of g.unMount){const at=get(o,Ke);at&&(at._f.refs?at._f.refs.every(Qe=>!live(Qe)):!live(at._f.ref))&&Xe(Ke)}g.unMount=new Set},oe=(Ke,at)=>!e.disabled&&(Ke&&at&&set(d,Ke,at),!deepEqual$1(qe(),l)),Ae=(Ke,at,Qe)=>generateWatchOutput(Ke,g,{...f.mount?d:isUndefined(at)?l:isString(Ke)?{[Ke]:at}:at},Qe,at),je=Ke=>compact(get(f.mount?d:l,Ke,e.shouldUnregister?get(l,Ke,[]):[])),Ne=(Ke,at,Qe={})=>{const ct=get(o,Ke);let ft=at;if(ct){const dt=ct._f;dt&&(!dt.disabled&&set(d,Ke,getFieldValueAs(at,dt)),ft=isHTMLElement(dt.ref)&&isNullOrUndefined(at)?"":at,isMultipleSelect(dt.ref)?[...dt.ref.options].forEach(yt=>yt.selected=ft.includes(yt.value)):dt.refs?isCheckBoxInput(dt.ref)?dt.refs.forEach(yt=>{(!yt.defaultChecked||!yt.disabled)&&(Array.isArray(ft)?yt.checked=!!ft.find(zt=>zt===yt.value):yt.checked=ft===yt.value||!!ft)}):dt.refs.forEach(yt=>yt.checked=yt.value===ft):isFileInput(dt.ref)?dt.ref.value="":(dt.ref.value=ft,dt.ref.type||C.state.next({name:Ke,values:cloneObject(d)})))}(Qe.shouldDirty||Qe.shouldTouch)&&F(Ke,ft,Qe.shouldTouch,Qe.shouldDirty,!0),Qe.shouldValidate&&Be(Ke)},Oe=(Ke,at,Qe)=>{for(const ct in at){if(!at.hasOwnProperty(ct))return;const ft=at[ct],dt=Ke+"."+ct,yt=get(o,dt);(g.array.has(Ke)||isObject(ft)||yt&&!yt._f)&&!isDateObject(ft)?Oe(dt,ft,Qe):Ne(dt,ft,Qe)}},Fe=(Ke,at,Qe={})=>{const ct=get(o,Ke),ft=g.array.has(Ke),dt=cloneObject(at);set(d,Ke,dt),ft?(C.array.next({name:Ke,values:cloneObject(d)}),(S.isDirty||S.dirtyFields||R.isDirty||R.dirtyFields)&&Qe.shouldDirty&&C.state.next({name:Ke,dirtyFields:getDirtyFields(l,d),isDirty:oe(Ke,dt)})):ct&&!ct._f&&!isNullOrUndefined(dt)?Oe(Ke,dt,Qe):Ne(Ke,dt,Qe),isWatched(Ke,g)&&C.state.next({...n}),C.state.next({name:f.mount?Ke:void 0,values:cloneObject(d)})},ze=async Ke=>{f.mount=!0;const at=Ke.target;let Qe=at.name,ct=!0;const ft=get(o,Qe),dt=Yt=>{ct=Number.isNaN(Yt)||isDateObject(Yt)&&isNaN(Yt.getTime())||deepEqual$1(Yt,get(d,Qe,Yt))},yt=getValidationModes(e.mode),zt=getValidationModes(e.reValidateMode);if(ft){let Yt,or;const dr=at.type?getFieldValue(ft._f):getEventValue(Ke),mt=Ke.type===EVENTS.BLUR||Ke.type===EVENTS.FOCUS_OUT,Sr=!hasValidation(ft._f)&&!e.resolver&&!get(n.errors,Qe)&&!ft._f.deps||skipValidation(mt,get(n.touchedFields,Qe),n.isSubmitted,zt,yt),Rt=isWatched(Qe,g,mt);set(d,Qe,dr),mt?(ft._f.onBlur&&ft._f.onBlur(Ke),b&&b(0)):ft._f.onChange&&ft._f.onChange(Ke);const Zt=F(Qe,dr,mt),Kt=!isEmptyObject$1(Zt)||Rt;if(!mt&&C.state.next({name:Qe,type:Ke.type,values:cloneObject(d)}),Sr)return(S.isValid||R.isValid)&&(e.mode==="onBlur"?mt&&I():mt||I()),Kt&&C.state.next({name:Qe,...Rt?{}:Zt});if(!mt&&Rt&&C.state.next({...n}),e.resolver){const{errors:nr}=await te([Qe]);if(dt(dr),ct){const ur=schemaErrorLookup(n.errors,o,Qe),Nr=schemaErrorLookup(nr,o,ur.name||Qe);Yt=Nr.error,Qe=Nr.name,or=isEmptyObject$1(nr)}}else M([Qe],!0),Yt=(await validateField(ft,g.disabled,d,E,e.shouldUseNativeValidation))[Qe],M([Qe]),dt(dr),ct&&(Yt?or=!1:(S.isValid||R.isValid)&&(or=await se(o,!0)));ct&&(ft._f.deps&&Be(ft._f.deps),V(Qe,or,Yt,Zt))}},$e=(Ke,at)=>{if(get(n.errors,at)&&Ke.focus)return Ke.focus(),1},Be=async(Ke,at={})=>{let Qe,ct;const ft=convertToArrayPayload(Ke);if(e.resolver){const dt=await ne(isUndefined(Ke)?Ke:ft);Qe=isEmptyObject$1(dt),ct=Ke?!ft.some(yt=>get(dt,yt)):Qe}else Ke?(ct=(await Promise.all(ft.map(async dt=>{const yt=get(o,dt);return await se(yt&&yt._f?{[dt]:yt}:yt)}))).every(Boolean),!(!ct&&!n.isValid)&&I()):ct=Qe=await se(o);return C.state.next({...!isString(Ke)||(S.isValid||R.isValid)&&Qe!==n.isValid?{}:{name:Ke},...e.resolver||!Ke?{isValid:Qe}:{},errors:n.errors}),at.shouldFocus&&!ct&&iterateFieldsByAction(o,$e,Ke?ft:g.mount),ct},qe=Ke=>{const at={...f.mount?d:l};return isUndefined(Ke)?at:isString(Ke)?get(at,Ke):Ke.map(Qe=>get(at,Qe))},Ge=(Ke,at)=>({invalid:!!get((at||n).errors,Ke),isDirty:!!get((at||n).dirtyFields,Ke),error:get((at||n).errors,Ke),isValidating:!!get(n.validatingFields,Ke),isTouched:!!get((at||n).touchedFields,Ke)}),He=Ke=>{Ke&&convertToArrayPayload(Ke).forEach(at=>unset(n.errors,at)),C.state.next({errors:Ke?n.errors:{}})},Ze=(Ke,at,Qe)=>{const ct=(get(o,Ke,{_f:{}})._f||{}).ref,ft=get(n.errors,Ke)||{},{ref:dt,message:yt,type:zt,...Yt}=ft;set(n.errors,Ke,{...Yt,...at,ref:ct}),C.state.next({name:Ke,errors:n.errors,isValid:!1}),Qe&&Qe.shouldFocus&&ct&&ct.focus&&ct.focus()},tt=(Ke,at)=>isFunction$3(Ke)?C.state.subscribe({next:Qe=>Ke(Ae(void 0,at),Qe)}):Ae(Ke,at,!0),Ye=Ke=>C.state.subscribe({next:at=>{shouldSubscribeByName(Ke.name,at.name,Ke.exact)&&shouldRenderFormState(at,Ke.formState||S,qt,Ke.reRenderRoot)&&Ke.callback({values:{...d},...n,...at})}}).unsubscribe,rt=Ke=>(f.mount=!0,R={...R,...Ke.formState},Ye({...Ke,formState:R})),Xe=(Ke,at={})=>{for(const Qe of Ke?convertToArrayPayload(Ke):g.mount)g.mount.delete(Qe),g.array.delete(Qe),at.keepValue||(unset(o,Qe),unset(d,Qe)),!at.keepError&&unset(n.errors,Qe),!at.keepDirty&&unset(n.dirtyFields,Qe),!at.keepTouched&&unset(n.touchedFields,Qe),!at.keepIsValidating&&unset(n.validatingFields,Qe),!e.shouldUnregister&&!at.keepDefaultValue&&unset(l,Qe);C.state.next({values:cloneObject(d)}),C.state.next({...n,...at.keepDirty?{isDirty:oe()}:{}}),!at.keepIsValid&&I()},it=({disabled:Ke,name:at})=>{(isBoolean(Ke)&&f.mount||Ke||g.disabled.has(at))&&(Ke?g.disabled.add(at):g.disabled.delete(at))},et=(Ke,at={})=>{let Qe=get(o,Ke);const ct=isBoolean(at.disabled)||isBoolean(e.disabled);return set(o,Ke,{...Qe||{},_f:{...Qe&&Qe._f?Qe._f:{ref:{name:Ke}},name:Ke,mount:!0,...at}}),g.mount.add(Ke),Qe?it({disabled:isBoolean(at.disabled)?at.disabled:e.disabled,name:Ke}):Q(Ke,!0,at.value),{...ct?{disabled:at.disabled||e.disabled}:{},...e.progressive?{required:!!at.required,min:getRuleValue(at.min),max:getRuleValue(at.max),minLength:getRuleValue(at.minLength),maxLength:getRuleValue(at.maxLength),pattern:getRuleValue(at.pattern)}:{},name:Ke,onChange:ze,onBlur:ze,ref:ft=>{if(ft){et(Ke,at),Qe=get(o,Ke);const dt=isUndefined(ft.value)&&ft.querySelectorAll&&ft.querySelectorAll("input,select,textarea")[0]||ft,yt=isRadioOrCheckbox(dt),zt=Qe._f.refs||[];if(yt?zt.find(Yt=>Yt===dt):dt===Qe._f.ref)return;set(o,Ke,{_f:{...Qe._f,...yt?{refs:[...zt.filter(live),dt,...Array.isArray(get(l,Ke))?[{}]:[]],ref:{type:dt.type,name:Ke}}:{ref:dt}}}),Q(Ke,!1,void 0,dt)}else Qe=get(o,Ke,{}),Qe._f&&(Qe._f.mount=!1),(e.shouldUnregister||at.shouldUnregister)&&!(isNameInFieldArray(g.array,Ke)&&f.action)&&g.unMount.add(Ke)}}},st=()=>e.shouldFocusError&&iterateFieldsByAction(o,$e,g.mount),ot=Ke=>{isBoolean(Ke)&&(C.state.next({disabled:Ke}),iterateFieldsByAction(o,(at,Qe)=>{const ct=get(o,Qe);ct&&(at.disabled=ct._f.disabled||Ke,Array.isArray(ct._f.refs)&&ct._f.refs.forEach(ft=>{ft.disabled=ct._f.disabled||Ke}))},0,!1))},Ue=(Ke,at)=>async Qe=>{let ct;Qe&&(Qe.preventDefault&&Qe.preventDefault(),Qe.persist&&Qe.persist());let ft=cloneObject(d);if(C.state.next({isSubmitting:!0}),e.resolver){const{errors:dt,values:yt}=await te();n.errors=dt,ft=yt}else await se(o);if(g.disabled.size)for(const dt of g.disabled)set(ft,dt,void 0);if(unset(n.errors,"root"),isEmptyObject$1(n.errors)){C.state.next({errors:{}});try{await Ke(ft,Qe)}catch(dt){ct=dt}}else at&&await at({...n.errors},Qe),st(),setTimeout(st);if(C.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:isEmptyObject$1(n.errors)&&!ct,submitCount:n.submitCount+1,errors:n.errors}),ct)throw ct},Ct=(Ke,at={})=>{get(o,Ke)&&(isUndefined(at.defaultValue)?Fe(Ke,cloneObject(get(l,Ke))):(Fe(Ke,at.defaultValue),set(l,Ke,cloneObject(at.defaultValue))),at.keepTouched||unset(n.touchedFields,Ke),at.keepDirty||(unset(n.dirtyFields,Ke),n.isDirty=at.defaultValue?oe(Ke,cloneObject(get(l,Ke))):oe()),at.keepError||(unset(n.errors,Ke),S.isValid&&I()),C.state.next({...n}))},Je=(Ke,at={})=>{const Qe=Ke?cloneObject(Ke):l,ct=cloneObject(Qe),ft=isEmptyObject$1(Ke),dt=ft?l:ct;if(at.keepDefaultValues||(l=Qe),!at.keepValues){if(at.keepDirtyValues){const yt=new Set([...g.mount,...Object.keys(getDirtyFields(l,d))]);for(const zt of Array.from(yt))get(n.dirtyFields,zt)?set(dt,zt,get(d,zt)):Fe(zt,get(dt,zt))}else{if(isWeb&&isUndefined(Ke))for(const yt of g.mount){const zt=get(o,yt);if(zt&&zt._f){const Yt=Array.isArray(zt._f.refs)?zt._f.refs[0]:zt._f.ref;if(isHTMLElement(Yt)){const or=Yt.closest("form");if(or){or.reset();break}}}}for(const yt of g.mount)Fe(yt,get(dt,yt))}d=cloneObject(dt),C.array.next({values:{...dt}}),C.state.next({values:{...dt}})}g={mount:at.keepDirtyValues?g.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},f.mount=!S.isValid||!!at.keepIsValid||!!at.keepDirtyValues,f.watch=!!e.shouldUnregister,C.state.next({submitCount:at.keepSubmitCount?n.submitCount:0,isDirty:ft?!1:at.keepDirty?n.isDirty:!!(at.keepDefaultValues&&!deepEqual$1(Ke,l)),isSubmitted:at.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ft?{}:at.keepDirtyValues?at.keepDefaultValues&&d?getDirtyFields(l,d):n.dirtyFields:at.keepDefaultValues&&Ke?getDirtyFields(l,Ke):at.keepDirty?n.dirtyFields:{},touchedFields:at.keepTouched?n.touchedFields:{},errors:at.keepErrors?n.errors:{},isSubmitSuccessful:at.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},pt=(Ke,at)=>Je(isFunction$3(Ke)?Ke(d):Ke,at),Mt=(Ke,at={})=>{const Qe=get(o,Ke),ct=Qe&&Qe._f;if(ct){const ft=ct.refs?ct.refs[0]:ct.ref;ft.focus&&(ft.focus(),at.shouldSelect&&isFunction$3(ft.select)&&ft.select())}},qt=Ke=>{n={...n,...Ke}},Ft={control:{register:et,unregister:Xe,getFieldState:Ge,handleSubmit:Ue,setError:Ze,_subscribe:Ye,_runSchema:te,_focusError:st,_getWatch:Ae,_getDirty:oe,_setValid:I,_setFieldArray:j,_setDisabledField:it,_setErrors:z,_getFieldArray:je,_reset:Je,_resetDefaultValues:()=>isFunction$3(e.defaultValues)&&e.defaultValues().then(Ke=>{pt(Ke,e.resetOptions),C.state.next({isLoading:!1})}),_removeUnmounted:ge,_disableForm:ot,_subjects:C,_proxyFormState:S,get _fields(){return o},get _formValues(){return d},get _state(){return f},set _state(Ke){f=Ke},get _defaultValues(){return l},get _names(){return g},set _names(Ke){g=Ke},get _formState(){return n},get _options(){return e},set _options(Ke){e={...e,...Ke}}},subscribe:rt,trigger:Be,register:et,handleSubmit:Ue,watch:tt,setValue:Fe,getValues:qe,reset:pt,resetField:Ct,clearErrors:He,unregister:Xe,setError:Ze,setFocus:Mt,getFieldState:Ge};return{...Ft,formControl:Ft}}function useForm(t={}){const e=React.useRef(void 0),n=React.useRef(void 0),[o,l]=React.useState({isDirty:!1,isValidating:!1,isLoading:isFunction$3(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1,isReady:!1,defaultValues:isFunction$3(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...t.formControl?t.formControl:createFormControl(t),formState:o},t.formControl&&t.defaultValues&&!isFunction$3(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions));const d=e.current.control;return d._options=t,useIsomorphicLayoutEffect$1(()=>{const f=d._subscribe({formState:d._proxyFormState,callback:()=>l({...d._formState}),reRenderRoot:!0});return l(g=>({...g,isReady:!0})),d._formState.isReady=!0,f},[d]),React.useEffect(()=>d._disableForm(t.disabled),[d,t.disabled]),React.useEffect(()=>{t.mode&&(d._options.mode=t.mode),t.reValidateMode&&(d._options.reValidateMode=t.reValidateMode)},[d,t.mode,t.reValidateMode]),React.useEffect(()=>{t.errors&&(d._setErrors(t.errors),d._focusError())},[d,t.errors]),React.useEffect(()=>{t.shouldUnregister&&d._subjects.state.next({values:d._getWatch()})},[d,t.shouldUnregister]),React.useEffect(()=>{if(d._proxyFormState.isDirty){const f=d._getDirty();f!==o.isDirty&&d._subjects.state.next({isDirty:f})}},[d,o.isDirty]),React.useEffect(()=>{t.values&&!deepEqual$1(t.values,n.current)?(d._reset(t.values,d._options.resetOptions),n.current=t.values,l(f=>({...f}))):d._resetDefaultValues()},[d,t.values]),React.useEffect(()=>{d._state.mount||(d._setValid(),d._state.mount=!0),d._state.watch&&(d._state.watch=!1,d._subjects.state.next({...d._formState})),d._removeUnmounted()}),e.current.formState=getProxyFormState(o,d),e.current}var defaultErrorHandler=function(t){process.env.NODE_ENV!=="production"&&console.error(t)},defaultWarnHandler=function(t){process.env.NODE_ENV!=="production"&&console.warn(t)},DEFAULT_INTL_CONFIG={formats:{},messages:{},timeZone:void 0,defaultLocale:"en",defaultFormats:{},fallbackOnEmptyString:!0,onError:defaultErrorHandler,onWarn:defaultWarnHandler};function invariant(t,e,n){if(n===void 0&&(n=Error),!t)throw new n(e)}function invariantIntlContext(t){invariant(t,"[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.")}__assign$1(__assign$1({},DEFAULT_INTL_CONFIG),{textComponent:React__namespace.Fragment});var reactIs={exports:{}},reactIs_production_min={};/** @license React v16.13.1
1053
+ `+_r),Ue&&arrayForEach([Ae,je,Ne],Pr=>{_r=stringReplace(_r,Pr," ")}),Q&&Ft?Q.createHTML(_r):_r},e.setConfig=function(){let Wt=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};wr(Wt),pt=!0},e.clearConfig=function(){Ir=null,pt=!1},e.isValidAttribute=function(Wt,nt,It){Ir||wr({});const Ut=mr(Wt),cr=mr(nt);return sn(Ut,cr,It)},e.addHook=function(Wt,nt){typeof nt=="function"&&arrayPush(oe[Wt],nt)},e.removeHook=function(Wt,nt){if(nt!==void 0){const It=arrayLastIndexOf(oe[Wt],nt);return It===-1?void 0:arraySplice(oe[Wt],It,1)[0]}return arrayPop(oe[Wt])},e.removeHooks=function(Wt){oe[Wt]=[]},e.removeAllHooks=function(){oe=_createHooksMap()},e}var purify=createDOMPurify();function markdownToSafeHTML(t){var e=marked(t,{async:!1});return purify.sanitize(e,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","b","strong","i","em","u","s","sub","sup","mark","code","pre","blockquote","q","ul","ol","li","dl","dt","dd","p","div","span","br","hr","table","thead","tbody","tfoot","tr","th","td"]})}function SkeletonMessage({botStatus:t}){return jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx("div",{className:"h-8 w-8 mt-1 rounded-full bg-gray-300 animate-pulse flex-shrink-0"}),jsxRuntime.jsxs("div",{className:"flex flex-col max-w-[70%]",children:[jsxRuntime.jsxs("p",{className:"mb-1",children:["Assistant",jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground mt-1 ml-3",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]}),jsxRuntime.jsx("div",{className:"rounded-md p-3 break-words bg-white border rounded-tl-none",children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:t})]})})]})]})}function ChatMessages({messages:t,currentUserId:e,botStatus:n,isAssistantChat:o}){return jsxRuntime.jsxs("div",{children:[t.map(l=>{const d=l.fromPartnerID===e;return jsxRuntime.jsxs("div",{className:cn("flex items-start gap-2 mt-2 mb-2",d&&"flex-row-reverse"),children:[jsxRuntime.jsx(Avatar,{className:"h-8 w-8 mt-1",children:jsxRuntime.jsx(AvatarImage,{src:`https://api.dicebear.com/9.x/thumbs/svg?seed=${md5(l.senderName+l.fromPartnerID)}&flip=${d}`})}),jsxRuntime.jsxs("div",{className:"flex flex-col max-w-[70%]",children:[jsxRuntime.jsxs("p",{className:"mb-1",children:[l.senderName,jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground mt-1 ml-3",children:(()=>{const f=new Date(l.timestamp);return isToday(f)?f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):isYesterday(f)?`Yesterday, ${f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`:`${f.toLocaleDateString([],{month:"short",day:"numeric"})} ${f.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`})()})]}),jsxRuntime.jsx("div",{className:cn("rounded-md p-3 break-words [&_li]:ml-6 [&_li]:list-disc [&_h1]:text-lg [&_h1]:font-bold [&_h1]:mt-4 [&_h2]:font-bold [&_h2]:mt-4 [&_h3]:mt-4 ",d?"bg-primary text-white rounded-tr-none":"bg-white border rounded-tl-none"),children:parser(markdownToSafeHTML(l.content))})]})]},l.id)}),n!==""&&jsxRuntime.jsx(SkeletonMessage,{botStatus:n}),t.length===0&&!o&&jsxRuntime.jsx("div",{className:"text-center text-muted-foreground py-8",children:"No messages yet"}),t.length===0&&n===""&&o&&jsxRuntime.jsxs("div",{className:"text-center py-8",children:[jsxRuntime.jsx("p",{children:"The Randmar Assistant is ready to help you. Ask anything about products, orders, carts, shipments and tracking numbers."}),jsxRuntime.jsx("p",{children:jsxRuntime.jsx("strong",{children:'Try it now, type "my open orders"!'})})]})]})}var SWITCH_NAME="Switch",[createSwitchContext,createSwitchScope]=createContextScope(SWITCH_NAME),[SwitchProvider,useSwitchContext]=createSwitchContext(SWITCH_NAME),Switch$1=React__namespace.forwardRef((t,e)=>{const{__scopeSwitch:n,name:o,checked:l,defaultChecked:d,required:f,disabled:g,value:b="on",onCheckedChange:_,form:S,...R}=t,[C,E]=React__namespace.useState(null),A=useComposedRefs(e,z=>E(z)),I=React__namespace.useRef(!1),M=C?S||!!C.closest("form"):!0,[j,q]=useControllableState({prop:l,defaultProp:d??!1,onChange:_,caller:SWITCH_NAME});return jsxRuntime.jsxs(SwitchProvider,{scope:n,checked:j,disabled:g,children:[jsxRuntime.jsx(Primitive.button,{type:"button",role:"switch","aria-checked":j,"aria-required":f,"data-state":getState$2(j),"data-disabled":g?"":void 0,disabled:g,value:b,...R,ref:A,onClick:composeEventHandlers(t.onClick,z=>{q(Q=>!Q),M&&(I.current=z.isPropagationStopped(),I.current||z.stopPropagation())})}),M&&jsxRuntime.jsx(SwitchBubbleInput,{control:C,bubbles:!I.current,name:o,value:b,checked:j,required:f,disabled:g,form:S,style:{transform:"translateX(-100%)"}})]})});Switch$1.displayName=SWITCH_NAME;var THUMB_NAME="SwitchThumb",SwitchThumb=React__namespace.forwardRef((t,e)=>{const{__scopeSwitch:n,...o}=t,l=useSwitchContext(THUMB_NAME,n);return jsxRuntime.jsx(Primitive.span,{"data-state":getState$2(l.checked),"data-disabled":l.disabled?"":void 0,...o,ref:e})});SwitchThumb.displayName=THUMB_NAME;var BUBBLE_INPUT_NAME$2="SwitchBubbleInput",SwitchBubbleInput=React__namespace.forwardRef(({__scopeSwitch:t,control:e,checked:n,bubbles:o=!0,...l},d)=>{const f=React__namespace.useRef(null),g=useComposedRefs(f,d),b=usePrevious(n),_=useSize(e);return React__namespace.useEffect(()=>{const S=f.current;if(!S)return;const R=window.HTMLInputElement.prototype,E=Object.getOwnPropertyDescriptor(R,"checked").set;if(b!==n&&E){const A=new Event("click",{bubbles:o});E.call(S,n),S.dispatchEvent(A)}},[b,n,o]),jsxRuntime.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...l,tabIndex:-1,ref:g,style:{...l.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});SwitchBubbleInput.displayName=BUBBLE_INPUT_NAME$2;function getState$2(t){return t?"checked":"unchecked"}var Root$1=Switch$1,Thumb=SwitchThumb;const Switch=React__namespace.forwardRef(({className:t,...e},n)=>jsxRuntime.jsx(Root$1,{className:cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...e,ref:n,children:jsxRuntime.jsx(Thumb,{className:cn("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Switch.displayName=Root$1.displayName;const DebugMessageDisplay=({debugMessages:t})=>{const[e,n]=React.useState({}),o=l=>{n(d=>({...d,[l]:!d[l]}))};return jsxRuntime.jsx("div",{children:t.map((l,d)=>{if(typeof l=="string")return jsxRuntime.jsx("p",{className:"text-slate-600",children:l},d);{const f=e[d];return jsxRuntime.jsxs("div",{className:"cursor-pointer",onClick:()=>o(d),children:[jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("p",{className:"text-slate-600 mr-2",children:l[0]}),jsxRuntime.jsx("span",{className:"text-slate-500 text-xs",children:f?"▲":"▼"})]}),f&&jsxRuntime.jsx("p",{className:"text-slate-400 pl-4",children:l[1]})]},d)}})})},ASSISTANT_ID="RandmarAIChatAssistant",sortChats=(t,e)=>t.unread>0&&e.unread===0?-1:e.unread>0&&t.unread===0?1:t.name.localeCompare(e.name),ChatLayout=React.forwardRef(({userId:t,userName:e,inputRef:n,assistantOnly:o,className:l,initialPrompt:d},f)=>{const{data:g,refetch:b}=useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsQuery({routeApplicationId:t},{skip:o===!0}),[_]=usePostV4PartnerByApplicationIdAccountDebugFeedbackMutation(),[S,{isLoading:R}]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[C,E]=React.useState(!1),A=React.useRef(null),I=React.useRef(!1),[M]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[j]=usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdReadMutation(),[q]=useLazyGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdMessagesQuery(),{handleSubmitToBot:z,botMessages:Q,clearBotMessages:F,botReady:V,debugMessages:te,botStatus:ne,reset:se}=useAIAssistant({userId:t,smartAndSlow:C});React.useEffect(()=>{const Rt={partner1:t,partner2:ASSISTANT_ID,name:"Randmar Assistant",unread:0,pending:!1,messages:[],conversationID:-1};if(o===!0){Ge([Rt]);return}if(!g)return;(async()=>{const Kt=g.map(async ur=>{var Tr,gr,xr;const Nr=await q({routeApplicationId:t,conversationId:ur.ConversationId});return{partner1:ur.Participant1,partner2:ur.Participant2,name:((Tr=ur.Participant)==null?void 0:Tr.PublicName)??"missing public name",unread:((gr=Nr.data)==null?void 0:gr.filter(er=>!er.Read&&er.SenderId!=t).length)??0,pending:ur.Status!=="Approved",messages:((xr=Nr.data)==null?void 0:xr.map(er=>({id:"history"+er.MessageId,fromPartnerID:er.SenderId,toPartnerID:er.SenderId==ur.Participant1?ur.Participant2:ur.Participant1,senderName:er.SenderName??"missing name",timestamp:new Date(er.SentDate+"Z").getTime(),content:er.Content??"no content"})))??[],conversationID:ur.ConversationId}}),nr=await Promise.all(Kt);nr.sort(sortChats),Ge([Rt,...nr]),setTimeout(()=>{var ur;return(ur=Ue.current)==null?void 0:ur.focus()},50)})()},[g,o,t]);const[ge,oe]=React.useState("approved"),[Ae,je]=React.useState([t,ASSISTANT_ID]),[Ne,Oe]=React.useState(""),[Fe,ze]=React.useState(null),[$e,Be]=React.useState(null),[qe,Ge]=React.useState([]),[He,Ze]=React.useState(""),[tt,Ye]=React.useState(null),rt=React.useRef(null),Xe=React.useRef(null),[it,et]=React.useState(null),[st,ot]=React.useState([]),Ue=n||Xe,Ct=React.useRef(null),{toast:Je}=useToast(),pt=()=>qe.find(Rt=>Rt.partner1===(Ae==null?void 0:Ae[0])&&Rt.partner2===(Ae==null?void 0:Ae[1])),Mt=()=>(Ae==null?void 0:Ae[0])===ASSISTANT_ID||(Ae==null?void 0:Ae[1])===ASSISTANT_ID;function qt(){const Rt=pt();Rt&&(Mt()||j({routeApplicationId:t,conversationId:Rt.conversationID}))}React.useEffect(()=>{d&&V&&(I.current||Mt()&&(I.current=!0,Ke(d)))},[d,V,Ae,I]),React.useEffect(()=>{Fe&&Ae&&(Ke(Fe),ze(null))},[Fe,Ae]);const Ht=React.useMemo(()=>qe.filter(Rt=>{const Zt=Rt.name.toLowerCase().includes(He.toLowerCase());return ge==="approved"?Zt&&!Rt.pending:ge==="pending"?Zt&&Rt.pending:Zt}),[qe,He,ge]);React.useEffect(()=>{var Rt;it!==null&&(Je({title:"File attached",description:"Add your instruction before sending.",variant:"success"}),(Rt=Ue.current)==null||Rt.focus())},[it]),React.useEffect(()=>{Q.length!==0&&(Q.forEach(Rt=>{if(!Rt||Rt.isComponent)return;const Zt={id:Rt.timestamp.toString(),fromPartnerID:ASSISTANT_ID,toPartnerID:t,senderName:"Assistant",timestamp:Rt.timestamp.getTime(),content:Rt.content};Ft(Zt)}),F())},[Q]);function Ft(Rt){Ge(Zt=>Zt.map(Kt=>{let nr=Kt.partner1===Rt.fromPartnerID&&Kt.partner2===Rt.toPartnerID;return nr||(nr=Kt.partner1===Rt.toPartnerID&&Kt.partner2===Rt.fromPartnerID),!nr||Kt.messages.some(ur=>ur.id===Rt.id)?Kt:(Be([Kt.partner1,Kt.partner2]),{...Kt,unread:Kt.unread+1,messages:[...Kt.messages,Rt]})}).sort(sortChats))}React.useEffect(()=>{if(o===!0)return;const Rt=new HubConnectionBuilder().withUrl("https://api.randmar.io/hub",{accessTokenFactory:()=>localStorage.getItem("access_token"),headers:{"X-Impersonated-Id":t}}).configureLogging(LogLevel.Information).withAutomaticReconnect().withHubProtocol(new JsonHubProtocol).build();return Rt.on("ReceiveMessage",Ft),Rt.start().catch(Zt=>console.error("Error connecting to SignalR hub:",Zt)),Ye(Rt),()=>{Rt&&Rt.stop()}},[t,o]),React.useEffect(()=>{($e==null?void 0:$e[0])!==(Ae==null?void 0:Ae[0])||($e==null?void 0:$e[1])!==(Ae==null?void 0:Ae[1])||(qt(),Ge(Rt=>Rt.map(Zt=>Zt.partner1===(Ae==null?void 0:Ae[0])&&Zt.partner2===(Ae==null?void 0:Ae[1])?{...Zt,unread:0}:Zt)),setTimeout(()=>{var Rt;return(Rt=rt.current)==null?void 0:Rt.scrollIntoView({behavior:"smooth"})},50))},[$e,Ae]),React.useEffect(()=>{var Zt;if(!Ae)return;const Rt=pt();Rt&&((Zt=Ue.current)==null||Zt.focus(),Rt.unread>0&&(qt(),Ge(Kt=>Kt.map(nr=>nr.partner1===Ae[0]&&nr.partner2===Ae[1]?{...nr,unread:0}:nr))),setTimeout(()=>{var Kt;return(Kt=rt.current)==null?void 0:Kt.scrollIntoView({behavior:"smooth"})},50))},[qe,Ae]);const Ke=Rt=>{if(!Ae)return;const Zt={id:crypto.randomUUID(),senderName:e,fromPartnerID:t,toPartnerID:Ae[0]===t?Ae[1]:Ae[0],content:Rt+(it?` (${it==null?void 0:it.name} attached)`:""),timestamp:Date.now()};Ge(Kt=>Kt.map(nr=>nr.partner1===Ae[0]&&nr.partner2===Ae[1]?{...nr,messages:[...nr.messages,Zt]}:nr)),Be([Ae[0],Ae[1]]),Zt.toPartnerID==ASSISTANT_ID?(z(Zt.content,it??void 0),it&&ot(Kt=>[...Kt,it.name])):tt.invoke("NewMessage",Zt).catch(Kt=>console.error("Error sending message:",Kt)),Oe(""),et(null),Ct.current&&(Ct.current.value="")},at=(Rt,Zt)=>{if(!qe.length||o!==!0&&!tt||!V)return!1;const Kt=qe.find(nr=>nr.conversationID===Rt);return Kt?(Kt.pending&&setTimeout(()=>oe("pending"),300),je([Kt.partner1,Kt.partner2]),Zt&&ze(Zt),!0):!1};if(React.useImperativeHandle(f,()=>({setActiveChatAndSendMessage:at})),!V)return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("div",{className:"flex items-center justify-center p-8",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),jsxRuntime.jsx("p",{children:"Loading API functions..."})]})})});const Qe=Rt=>{var Kt;if(!Mt())return;const Zt=(Kt=Rt.clipboardData)==null?void 0:Kt.items;if(Zt){for(let nr=0;nr<Zt.length;nr++)if(Zt[nr].type.indexOf("image")!==-1){const ur=Zt[nr].getAsFile();if(ur){et(ur);return}}}},ct=()=>{!Ne.trim()||!Ae||o!==!0&&!tt||Ke(Ne)},ft=Rt=>{Rt.target.files&&Rt.target.files[0]?et(Rt.target.files[0]):et(null)},dt=()=>{var Rt;(Rt=Ct.current)==null||Rt.click()},yt=()=>{var Rt;et(null),Je({title:"File removed",description:"No file will be sent to the assistant.",variant:"secondary"}),(Rt=Ue.current)==null||Rt.focus()},zt=()=>{const Zt={messages:qe.find(Kt=>Kt.partner1===ASSISTANT_ID||Kt.partner2===ASSISTANT_ID),debug:te};_({applicationId:t,emailAddress:e,body:Zt})},Yt=async()=>{A.current&&(A.current.disabled=!0),await M({routeApplicationId:t,partnerId:"2"}),await b()},or=()=>{Ge(Rt=>Rt.map(Kt=>Kt.partner1!==ASSISTANT_ID&&Kt.partner2!==ASSISTANT_ID?Kt:{...Kt,messages:[]})),ot([]),se()},dr=()=>{Ae&&S({routeApplicationId:t,partnerId:Ae[0]==t?Ae[1]:Ae[0]}).then(()=>{oe("approved")})},mt=pt(),Sr=qe.filter(Rt=>Rt.pending).length;return jsxRuntime.jsxs("div",{className:cn("flex overflow-hidden",l),children:[o!==!0&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"w-[260px] p-4 pt-3 flex flex-col border-r",children:[jsxRuntime.jsx("div",{className:"p-4 font-semibold border-b",children:"Communications"}),qe.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"p-2",children:jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(Search,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),jsxRuntime.jsx(Input,{placeholder:"Search chats...",className:"pl-8 h-9",value:He,onChange:Rt=>Ze(Rt.target.value)})]})}),jsxRuntime.jsx(Tabs,{value:ge,onValueChange:oe,className:"w-full mb-1",children:jsxRuntime.jsxs(TabsList,{className:"grid grid-cols-6 h-9 mx-2",children:[jsxRuntime.jsx(TabsTrigger,{value:"approved",className:"text-xs col-span-3",children:"Approved"}),jsxRuntime.jsxs(TabsTrigger,{value:"pending",className:"text-xs col-span-3",children:["Pending ",Sr>0&&`(${Sr})`]})]})})]}),jsxRuntime.jsx("div",{className:"mt-1 mb-1",children:qe.findIndex(Rt=>Rt.partner1==="2"||Rt.partner2==="2")<0?jsxRuntime.jsx(Button,{className:"w-full",ref:A,onClick:()=>Yt(),children:"Chat with Randmar"},"b1"):ge==="approved"&&qe.length>=5?null:jsxRuntime.jsx("a",{target:"_blank",href:`https://dashboard.randmar.io/${t}/ExploreManufacturers`,children:jsxRuntime.jsx(Button,{className:"w-full",children:"Explore manufacturers"},"b2")})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1",children:qe.length&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ChatList,{userId:t,chats:Ht.filter(Rt=>Rt.partner1!=ASSISTANT_ID&&Rt.partner2!=ASSISTANT_ID),activeChat:mt??null,onSelectChat:je,assistantChat:qe.find(Rt=>Rt.partner1==ASSISTANT_ID||Rt.partner2==ASSISTANT_ID)})})})]})}),jsxRuntime.jsx("div",{className:"flex-5 flex flex-col",children:Ae?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:Ae[0]==ASSISTANT_ID||Ae[1]==ASSISTANT_ID?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Avatar,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:jsxRuntime.jsx(Bot,{className:"text-primary fill-white min-h-full"})}),jsxRuntime.jsx("div",{className:"ml-3 font-medium",children:"Randmar Assistant"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 ml-auto",children:[jsxRuntime.jsx(Switch,{id:"smartSwitch",disabled:!!ne,checked:C,onCheckedChange:Rt=>{or(),setTimeout(()=>E(Rt),20)}}),jsxRuntime.jsx(Label$2,{htmlFor:"smartSwitch",children:"Think harder"})]}),jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"ml-1",onClick:()=>or(),children:jsxRuntime.jsx(MessageCircleX,{className:"h-5 w-5"})}),jsxRuntime.jsx(Button,{variant:"ghost",size:"icon",className:"ml-1",confirmationDialog:{title:"Report Issue",content:"This action will send a copy of your chat to Randmar. Send it?",onConfirm:()=>zt()},children:jsxRuntime.jsx(MessageSquareShare,{className:"h-5 w-5"})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Avatar,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:[jsxRuntime.jsx(AvatarImage,{src:`https://api.randmar.io/v4/Partner/${Ae[0]===t?Ae[1]:Ae[0]}/Account/Logo?height=72&width=72`,className:" object-contain "}),jsxRuntime.jsx(AvatarFallback,{children:jsxRuntime.jsx(Handshake,{className:"text-primary fill-white min-h-full"})})]}),jsxRuntime.jsx("div",{className:"ml-3 font-medium",children:mt==null?void 0:mt.name}),jsxRuntime.jsx("div",{className:"flex items-center space-x-2 ml-auto",children:jsxRuntime.jsx("a",{href:`https://dashboard.randmar.io/${t}/Partner/${Ae[0]===t?Ae[1]:Ae[0]}`,target:"_blank",children:jsxRuntime.jsx(Button,{children:"View Partner"})})})]})}),mt!=null&&mt.pending&&mt.partner1==t?jsxRuntime.jsx("p",{className:"mt-8 p-2 mx-auto",children:"This conversation is awaiting approval by the other party — please check back later."}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:[jsxRuntime.jsx(ChatMessages,{messages:(mt==null?void 0:mt.messages)??[],currentUserId:t,isAssistantChat:Mt(),botStatus:Mt()?ne:""}),jsxRuntime.jsx("div",{ref:rt})]}),jsxRuntime.jsxs("div",{className:"p-4 border-t border-r flex",children:[(mt==null?void 0:mt.pending)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button,{disabled:R,onClick:()=>dr(),children:[jsxRuntime.jsx(Handshake,{}),"Accept Conversation Request"]}),jsxRuntime.jsxs(Button,{disabled:!0,className:"ml-2",children:[jsxRuntime.jsx(ThumbsDown,{}),"Block Partner"]})]}),jsxRuntime.jsx(Textarea,{ref:Ue,placeholder:"Type a message...",value:Ne,onPaste:Qe,onChange:Rt=>Oe(Rt.target.value),onKeyDown:Rt=>{Rt.key!=="Enter"||Rt.shiftKey||(Rt.preventDefault(),ct())},className:mt!=null&&mt.pending?"collapse":"flex-1 resize-none"}),jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(Button,{size:"icon",variant:"default",className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:!!ne||(mt==null?void 0:mt.pending),onClick:ct,children:jsxRuntime.jsx(Send,{className:"h-6 w-6"})}),Mt()&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Input,{type:"file",onChange:ft,className:"hidden",ref:Ct}),jsxRuntime.jsx(Button,{size:"icon",variant:"default",onClick:dt,className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:ne!==""||(mt==null?void 0:mt.pending)||!!it,children:jsxRuntime.jsx(Paperclip,{className:"h-5 w-5"})}),jsxRuntime.jsx(Button,{size:"icon",variant:"default",onClick:yt,className:mt!=null&&mt.pending?"collapse":"ml-2 h-8 w-8",disabled:ne!==""||(mt==null?void 0:mt.pending)||!it,children:jsxRuntime.jsx(Trash,{className:"h-5 w-5"})})]})]})]})]})]}):jsxRuntime.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a chat to start messaging"})}),jsxRuntime.jsx("div",{"data-thin":Mt(),className:"w-[480px] flex flex-col border-l flex-4 data-[thin=true]:flex-2",children:Mt()?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:jsxRuntime.jsx("p",{className:"h-9 text-base/9",children:"Sources and System Info"})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsxs("div",{className:"space-y-2",children:[it?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsx(File,{})," ",it.name," (pending send...)"]})}):st.length?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("p",{children:"No files attached to this conversation yet."}),st.slice().reverse().map(Rt=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsx(File,{})," ",Rt]})}))]})}),jsxRuntime.jsx(ScrollArea,{className:"flex-4 border-t pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsx("div",{className:"space-y-2",children:jsxRuntime.jsx(DebugMessageDisplay,{debugMessages:te})})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex items-center p-4 border-b",children:jsxRuntime.jsx("p",{className:"h-9 text-base/9",children:"Partner Overview"})}),jsxRuntime.jsx(ScrollArea,{className:"flex-1 pl-2 pr-2 bg-slate-50",children:jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(PartnerRelationshipPage,{applicationId:t,partnerId:((Ae==null?void 0:Ae[0])===t?Ae[1]:Ae==null?void 0:Ae[0])??t,userEmail:e,shopifyHostName:void 0,isSuperAdmin:!1})})})]})})]})});function UnsavedChangesDialog({isOpen:t,onClose:e,onConfirm:n,title:o,description:l,confirmText:d="Confirm",cancelText:f="Cancel"}){return jsxRuntime.jsx(Dialog,{open:t,onOpenChange:e,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:o}),jsxRuntime.jsx(DialogDescription,{children:l})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:e,children:f}),jsxRuntime.jsx(Button,{onClick:n,children:d})]})]})})}function useRouterNavigationGuard(t){const[e,n]=React.useState(!1),o=reactRouterDom.useBlocker(React.useCallback(({currentLocation:g,nextLocation:b})=>{const _=g.pathname!==b.pathname||g.search!==b.search||g.hash!==b.hash;return t()&&_},[t]));React.useEffect(()=>{o.state==="blocked"&&n(!0)},[o]),React.useEffect(()=>{const g=b=>{if(t())return b.preventDefault(),"You have unsaved changes. Are you sure you want to leave?"};return window.addEventListener("beforeunload",g),()=>{window.removeEventListener("beforeunload",g)}},[t]);const l=React.useCallback(()=>{n(!1),o.state==="blocked"&&o.proceed()},[o]),d=React.useCallback(()=>{n(!1),o.state==="blocked"&&o.reset()},[o]),f=React.useCallback(()=>jsxRuntime.jsx(UnsavedChangesDialog,{isOpen:e,onClose:d,onConfirm:l,title:"Unsaved Changes",description:"You have unsaved changes. Are you sure you want to leave? Your changes will be lost.",confirmText:"Discard Changes",cancelText:"Stay on Page"}),[e,d,l]);return{showDialog:e,handleConfirm:l,handleCancel:d,NavigationGuardDialog:f}}var isCheckBoxInput=t=>t.type==="checkbox",isDateObject=t=>t instanceof Date,isNullOrUndefined=t=>t==null;const isObjectType=t=>typeof t=="object";var isObject=t=>!isNullOrUndefined(t)&&!Array.isArray(t)&&isObjectType(t)&&!isDateObject(t),getEventValue=t=>isObject(t)&&t.target?isCheckBoxInput(t.target)?t.target.checked:t.target.value:t,getNodeParentName=t=>t.substring(0,t.search(/\.\d+(\.|$)/))||t,isNameInFieldArray=(t,e)=>t.has(getNodeParentName(e)),isPlainObject$1=t=>{const e=t.constructor&&t.constructor.prototype;return isObject(e)&&e.hasOwnProperty("isPrototypeOf")},isWeb=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function cloneObject(t){let e;const n=Array.isArray(t),o=typeof FileList<"u"?t instanceof FileList:!1;if(t instanceof Date)e=new Date(t);else if(t instanceof Set)e=new Set(t);else if(!(isWeb&&(t instanceof Blob||o))&&(n||isObject(t)))if(e=n?[]:{},!n&&!isPlainObject$1(t))e=t;else for(const l in t)t.hasOwnProperty(l)&&(e[l]=cloneObject(t[l]));else return t;return e}var compact=t=>Array.isArray(t)?t.filter(Boolean):[],isUndefined=t=>t===void 0,get=(t,e,n)=>{if(!e||!isObject(t))return n;const o=compact(e.split(/[,[\].]+?/)).reduce((l,d)=>isNullOrUndefined(l)?l:l[d],t);return isUndefined(o)||o===t?isUndefined(t[e])?n:t[e]:o},isBoolean=t=>typeof t=="boolean",isKey=t=>/^\w*$/.test(t),stringToPath=t=>compact(t.replace(/["|']|\]/g,"").split(/\.|\[/)),set=(t,e,n)=>{let o=-1;const l=isKey(e)?[e]:stringToPath(e),d=l.length,f=d-1;for(;++o<d;){const g=l[o];let b=n;if(o!==f){const _=t[g];b=isObject(_)||Array.isArray(_)?_:isNaN(+l[o+1])?{}:[]}if(g==="__proto__"||g==="constructor"||g==="prototype")return;t[g]=b,t=t[g]}};const EVENTS={BLUR:"blur",FOCUS_OUT:"focusout"},VALIDATION_MODE={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},INPUT_VALIDATION_RULES={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};React.createContext(null);var getProxyFormState=(t,e,n,o=!0)=>{const l={defaultValues:e._defaultValues};for(const d in t)Object.defineProperty(l,d,{get:()=>{const f=d;return e._proxyFormState[f]!==VALIDATION_MODE.all&&(e._proxyFormState[f]=!o||VALIDATION_MODE.all),t[f]}});return l};const useIsomorphicLayoutEffect$1=typeof window<"u"?React__namespace.useLayoutEffect:React__namespace.useEffect;var isString=t=>typeof t=="string",generateWatchOutput=(t,e,n,o,l)=>isString(t)?(o&&e.watch.add(t),get(n,t,l)):Array.isArray(t)?t.map(d=>(o&&e.watch.add(d),get(n,d))):(o&&(e.watchAll=!0),n),appendErrors=(t,e,n,o,l)=>e?{...n[t],types:{...n[t]&&n[t].types?n[t].types:{},[o]:l||!0}}:{},convertToArrayPayload=t=>Array.isArray(t)?t:[t],createSubject=()=>{let t=[];return{get observers(){return t},next:l=>{for(const d of t)d.next&&d.next(l)},subscribe:l=>(t.push(l),{unsubscribe:()=>{t=t.filter(d=>d!==l)}}),unsubscribe:()=>{t=[]}}},isPrimitive=t=>isNullOrUndefined(t)||!isObjectType(t);function deepEqual$1(t,e){if(isPrimitive(t)||isPrimitive(e))return t===e;if(isDateObject(t)&&isDateObject(e))return t.getTime()===e.getTime();const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const l of n){const d=t[l];if(!o.includes(l))return!1;if(l!=="ref"){const f=e[l];if(isDateObject(d)&&isDateObject(f)||isObject(d)&&isObject(f)||Array.isArray(d)&&Array.isArray(f)?!deepEqual$1(d,f):d!==f)return!1}}return!0}var isEmptyObject$1=t=>isObject(t)&&!Object.keys(t).length,isFileInput=t=>t.type==="file",isFunction$3=t=>typeof t=="function",isHTMLElement=t=>{if(!isWeb)return!1;const e=t?t.ownerDocument:0;return t instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},isMultipleSelect=t=>t.type==="select-multiple",isRadioInput=t=>t.type==="radio",isRadioOrCheckbox=t=>isRadioInput(t)||isCheckBoxInput(t),live=t=>isHTMLElement(t)&&t.isConnected;function baseGet(t,e){const n=e.slice(0,-1).length;let o=0;for(;o<n;)t=isUndefined(t)?o++:t[e[o++]];return t}function isEmptyArray(t){for(const e in t)if(t.hasOwnProperty(e)&&!isUndefined(t[e]))return!1;return!0}function unset(t,e){const n=Array.isArray(e)?e:isKey(e)?[e]:stringToPath(e),o=n.length===1?t:baseGet(t,n),l=n.length-1,d=n[l];return o&&delete o[d],l!==0&&(isObject(o)&&isEmptyObject$1(o)||Array.isArray(o)&&isEmptyArray(o))&&unset(t,n.slice(0,-1)),t}var objectHasFunction=t=>{for(const e in t)if(isFunction$3(t[e]))return!0;return!1};function markFieldsDirty(t,e={}){const n=Array.isArray(t);if(isObject(t)||n)for(const o in t)Array.isArray(t[o])||isObject(t[o])&&!objectHasFunction(t[o])?(e[o]=Array.isArray(t[o])?[]:{},markFieldsDirty(t[o],e[o])):isNullOrUndefined(t[o])||(e[o]=!0);return e}function getDirtyFieldsFromDefaultValues(t,e,n){const o=Array.isArray(t);if(isObject(t)||o)for(const l in t)Array.isArray(t[l])||isObject(t[l])&&!objectHasFunction(t[l])?isUndefined(e)||isPrimitive(n[l])?n[l]=Array.isArray(t[l])?markFieldsDirty(t[l],[]):{...markFieldsDirty(t[l])}:getDirtyFieldsFromDefaultValues(t[l],isNullOrUndefined(e)?{}:e[l],n[l]):n[l]=!deepEqual$1(t[l],e[l]);return n}var getDirtyFields=(t,e)=>getDirtyFieldsFromDefaultValues(t,e,markFieldsDirty(e));const defaultResult={value:!1,isValid:!1},validResult={value:!0,isValid:!0};var getCheckboxValue=t=>{if(Array.isArray(t)){if(t.length>1){const e=t.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:e,isValid:!!e.length}}return t[0].checked&&!t[0].disabled?t[0].attributes&&!isUndefined(t[0].attributes.value)?isUndefined(t[0].value)||t[0].value===""?validResult:{value:t[0].value,isValid:!0}:validResult:defaultResult}return defaultResult},getFieldValueAs=(t,{valueAsNumber:e,valueAsDate:n,setValueAs:o})=>isUndefined(t)?t:e?t===""?NaN:t&&+t:n&&isString(t)?new Date(t):o?o(t):t;const defaultReturn={isValid:!1,value:null};var getRadioValue=t=>Array.isArray(t)?t.reduce((e,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:e,defaultReturn):defaultReturn;function getFieldValue(t){const e=t.ref;return isFileInput(e)?e.files:isRadioInput(e)?getRadioValue(t.refs).value:isMultipleSelect(e)?[...e.selectedOptions].map(({value:n})=>n):isCheckBoxInput(e)?getCheckboxValue(t.refs).value:getFieldValueAs(isUndefined(e.value)?t.ref.value:e.value,t)}var getResolverOptions=(t,e,n,o)=>{const l={};for(const d of t){const f=get(e,d);f&&set(l,d,f._f)}return{criteriaMode:n,names:[...t],fields:l,shouldUseNativeValidation:o}},isRegex=t=>t instanceof RegExp,getRuleValue=t=>isUndefined(t)?t:isRegex(t)?t.source:isObject(t)?isRegex(t.value)?t.value.source:t.value:t,getValidationModes=t=>({isOnSubmit:!t||t===VALIDATION_MODE.onSubmit,isOnBlur:t===VALIDATION_MODE.onBlur,isOnChange:t===VALIDATION_MODE.onChange,isOnAll:t===VALIDATION_MODE.all,isOnTouch:t===VALIDATION_MODE.onTouched});const ASYNC_FUNCTION="AsyncFunction";var hasPromiseValidation=t=>!!t&&!!t.validate&&!!(isFunction$3(t.validate)&&t.validate.constructor.name===ASYNC_FUNCTION||isObject(t.validate)&&Object.values(t.validate).find(e=>e.constructor.name===ASYNC_FUNCTION)),hasValidation=t=>t.mount&&(t.required||t.min||t.max||t.maxLength||t.minLength||t.pattern||t.validate),isWatched=(t,e,n)=>!n&&(e.watchAll||e.watch.has(t)||[...e.watch].some(o=>t.startsWith(o)&&/^\.\w+/.test(t.slice(o.length))));const iterateFieldsByAction=(t,e,n,o)=>{for(const l of n||Object.keys(t)){const d=get(t,l);if(d){const{_f:f,...g}=d;if(f){if(f.refs&&f.refs[0]&&e(f.refs[0],l)&&!o)return!0;if(f.ref&&e(f.ref,f.name)&&!o)return!0;if(iterateFieldsByAction(g,e))break}else if(isObject(g)&&iterateFieldsByAction(g,e))break}}};function schemaErrorLookup(t,e,n){const o=get(t,n);if(o||isKey(n))return{error:o,name:n};const l=n.split(".");for(;l.length;){const d=l.join("."),f=get(e,d),g=get(t,d);if(f&&!Array.isArray(f)&&n!==d)return{name:n};if(g&&g.type)return{name:d,error:g};if(g&&g.root&&g.root.type)return{name:`${d}.root`,error:g.root};l.pop()}return{name:n}}var shouldRenderFormState=(t,e,n,o)=>{n(t);const{name:l,...d}=t;return isEmptyObject$1(d)||Object.keys(d).length>=Object.keys(e).length||Object.keys(d).find(f=>e[f]===(!o||VALIDATION_MODE.all))},shouldSubscribeByName=(t,e,n)=>!t||!e||t===e||convertToArrayPayload(t).some(o=>o&&(n?o===e:o.startsWith(e)||e.startsWith(o))),skipValidation=(t,e,n,o,l)=>l.isOnAll?!1:!n&&l.isOnTouch?!(e||t):(n?o.isOnBlur:l.isOnBlur)?!t:(n?o.isOnChange:l.isOnChange)?t:!0,unsetEmptyArray=(t,e)=>!compact(get(t,e)).length&&unset(t,e),updateFieldArrayRootError=(t,e,n)=>{const o=convertToArrayPayload(get(t,n));return set(o,"root",e[n]),set(t,n,o),t},isMessage=t=>isString(t);function getValidateError(t,e,n="validate"){if(isMessage(t)||Array.isArray(t)&&t.every(isMessage)||isBoolean(t)&&!t)return{type:n,message:isMessage(t)?t:"",ref:e}}var getValueAndMessage=t=>isObject(t)&&!isRegex(t)?t:{value:t,message:""},validateField=async(t,e,n,o,l,d)=>{const{ref:f,refs:g,required:b,maxLength:_,minLength:S,min:R,max:C,pattern:E,validate:A,name:I,valueAsNumber:M,mount:j}=t._f,q=get(n,I);if(!j||e.has(I))return{};const z=g?g[0]:f,Q=Ae=>{l&&z.reportValidity&&(z.setCustomValidity(isBoolean(Ae)?"":Ae||""),z.reportValidity())},F={},V=isRadioInput(f),te=isCheckBoxInput(f),ne=V||te,se=(M||isFileInput(f))&&isUndefined(f.value)&&isUndefined(q)||isHTMLElement(f)&&f.value===""||q===""||Array.isArray(q)&&!q.length,ge=appendErrors.bind(null,I,o,F),oe=(Ae,je,Ne,Oe=INPUT_VALIDATION_RULES.maxLength,Fe=INPUT_VALIDATION_RULES.minLength)=>{const ze=Ae?je:Ne;F[I]={type:Ae?Oe:Fe,message:ze,ref:f,...ge(Ae?Oe:Fe,ze)}};if(d?!Array.isArray(q)||!q.length:b&&(!ne&&(se||isNullOrUndefined(q))||isBoolean(q)&&!q||te&&!getCheckboxValue(g).isValid||V&&!getRadioValue(g).isValid)){const{value:Ae,message:je}=isMessage(b)?{value:!!b,message:b}:getValueAndMessage(b);if(Ae&&(F[I]={type:INPUT_VALIDATION_RULES.required,message:je,ref:z,...ge(INPUT_VALIDATION_RULES.required,je)},!o))return Q(je),F}if(!se&&(!isNullOrUndefined(R)||!isNullOrUndefined(C))){let Ae,je;const Ne=getValueAndMessage(C),Oe=getValueAndMessage(R);if(!isNullOrUndefined(q)&&!isNaN(q)){const Fe=f.valueAsNumber||q&&+q;isNullOrUndefined(Ne.value)||(Ae=Fe>Ne.value),isNullOrUndefined(Oe.value)||(je=Fe<Oe.value)}else{const Fe=f.valueAsDate||new Date(q),ze=qe=>new Date(new Date().toDateString()+" "+qe),$e=f.type=="time",Be=f.type=="week";isString(Ne.value)&&q&&(Ae=$e?ze(q)>ze(Ne.value):Be?q>Ne.value:Fe>new Date(Ne.value)),isString(Oe.value)&&q&&(je=$e?ze(q)<ze(Oe.value):Be?q<Oe.value:Fe<new Date(Oe.value))}if((Ae||je)&&(oe(!!Ae,Ne.message,Oe.message,INPUT_VALIDATION_RULES.max,INPUT_VALIDATION_RULES.min),!o))return Q(F[I].message),F}if((_||S)&&!se&&(isString(q)||d&&Array.isArray(q))){const Ae=getValueAndMessage(_),je=getValueAndMessage(S),Ne=!isNullOrUndefined(Ae.value)&&q.length>+Ae.value,Oe=!isNullOrUndefined(je.value)&&q.length<+je.value;if((Ne||Oe)&&(oe(Ne,Ae.message,je.message),!o))return Q(F[I].message),F}if(E&&!se&&isString(q)){const{value:Ae,message:je}=getValueAndMessage(E);if(isRegex(Ae)&&!q.match(Ae)&&(F[I]={type:INPUT_VALIDATION_RULES.pattern,message:je,ref:f,...ge(INPUT_VALIDATION_RULES.pattern,je)},!o))return Q(je),F}if(A){if(isFunction$3(A)){const Ae=await A(q,n),je=getValidateError(Ae,z);if(je&&(F[I]={...je,...ge(INPUT_VALIDATION_RULES.validate,je.message)},!o))return Q(je.message),F}else if(isObject(A)){let Ae={};for(const je in A){if(!isEmptyObject$1(Ae)&&!o)break;const Ne=getValidateError(await A[je](q,n),z,je);Ne&&(Ae={...Ne,...ge(je,Ne.message)},Q(Ne.message),o&&(F[I]=Ae))}if(!isEmptyObject$1(Ae)&&(F[I]={ref:z,...Ae},!o))return F}}return Q(!0),F};const defaultOptions$1={mode:VALIDATION_MODE.onSubmit,reValidateMode:VALIDATION_MODE.onChange,shouldFocusError:!0};function createFormControl(t={}){let e={...defaultOptions$1,...t},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:isFunction$3(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1};const o={};let l=isObject(e.defaultValues)||isObject(e.values)?cloneObject(e.defaultValues||e.values)||{}:{},d=e.shouldUnregister?{}:cloneObject(l),f={action:!1,mount:!1,watch:!1},g={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},b,_=0;const S={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let R={...S};const C={array:createSubject(),state:createSubject()},E=e.criteriaMode===VALIDATION_MODE.all,A=Ke=>at=>{clearTimeout(_),_=setTimeout(Ke,at)},I=async Ke=>{if(!e.disabled&&(S.isValid||R.isValid||Ke)){const at=e.resolver?isEmptyObject$1((await te()).errors):await se(o,!0);at!==n.isValid&&C.state.next({isValid:at})}},M=(Ke,at)=>{!e.disabled&&(S.isValidating||S.validatingFields||R.isValidating||R.validatingFields)&&((Ke||Array.from(g.mount)).forEach(Qe=>{Qe&&(at?set(n.validatingFields,Qe,at):unset(n.validatingFields,Qe))}),C.state.next({validatingFields:n.validatingFields,isValidating:!isEmptyObject$1(n.validatingFields)}))},j=(Ke,at=[],Qe,ct,ft=!0,dt=!0)=>{if(ct&&Qe&&!e.disabled){if(f.action=!0,dt&&Array.isArray(get(o,Ke))){const yt=Qe(get(o,Ke),ct.argA,ct.argB);ft&&set(o,Ke,yt)}if(dt&&Array.isArray(get(n.errors,Ke))){const yt=Qe(get(n.errors,Ke),ct.argA,ct.argB);ft&&set(n.errors,Ke,yt),unsetEmptyArray(n.errors,Ke)}if((S.touchedFields||R.touchedFields)&&dt&&Array.isArray(get(n.touchedFields,Ke))){const yt=Qe(get(n.touchedFields,Ke),ct.argA,ct.argB);ft&&set(n.touchedFields,Ke,yt)}(S.dirtyFields||R.dirtyFields)&&(n.dirtyFields=getDirtyFields(l,d)),C.state.next({name:Ke,isDirty:oe(Ke,at),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else set(d,Ke,at)},q=(Ke,at)=>{set(n.errors,Ke,at),C.state.next({errors:n.errors})},z=Ke=>{n.errors=Ke,C.state.next({errors:n.errors,isValid:!1})},Q=(Ke,at,Qe,ct)=>{const ft=get(o,Ke);if(ft){const dt=get(d,Ke,isUndefined(Qe)?get(l,Ke):Qe);isUndefined(dt)||ct&&ct.defaultChecked||at?set(d,Ke,at?dt:getFieldValue(ft._f)):Ne(Ke,dt),f.mount&&I()}},F=(Ke,at,Qe,ct,ft)=>{let dt=!1,yt=!1;const zt={name:Ke};if(!e.disabled){if(!Qe||ct){(S.isDirty||R.isDirty)&&(yt=n.isDirty,n.isDirty=zt.isDirty=oe(),dt=yt!==zt.isDirty);const Yt=deepEqual$1(get(l,Ke),at);yt=!!get(n.dirtyFields,Ke),Yt?unset(n.dirtyFields,Ke):set(n.dirtyFields,Ke,!0),zt.dirtyFields=n.dirtyFields,dt=dt||(S.dirtyFields||R.dirtyFields)&&yt!==!Yt}if(Qe){const Yt=get(n.touchedFields,Ke);Yt||(set(n.touchedFields,Ke,Qe),zt.touchedFields=n.touchedFields,dt=dt||(S.touchedFields||R.touchedFields)&&Yt!==Qe)}dt&&ft&&C.state.next(zt)}return dt?zt:{}},V=(Ke,at,Qe,ct)=>{const ft=get(n.errors,Ke),dt=(S.isValid||R.isValid)&&isBoolean(at)&&n.isValid!==at;if(e.delayError&&Qe?(b=A(()=>q(Ke,Qe)),b(e.delayError)):(clearTimeout(_),b=null,Qe?set(n.errors,Ke,Qe):unset(n.errors,Ke)),(Qe?!deepEqual$1(ft,Qe):ft)||!isEmptyObject$1(ct)||dt){const yt={...ct,...dt&&isBoolean(at)?{isValid:at}:{},errors:n.errors,name:Ke};n={...n,...yt},C.state.next(yt)}},te=async Ke=>{M(Ke,!0);const at=await e.resolver(d,e.context,getResolverOptions(Ke||g.mount,o,e.criteriaMode,e.shouldUseNativeValidation));return M(Ke),at},ne=async Ke=>{const{errors:at}=await te(Ke);if(Ke)for(const Qe of Ke){const ct=get(at,Qe);ct?set(n.errors,Qe,ct):unset(n.errors,Qe)}else n.errors=at;return at},se=async(Ke,at,Qe={valid:!0})=>{for(const ct in Ke){const ft=Ke[ct];if(ft){const{_f:dt,...yt}=ft;if(dt){const zt=g.array.has(dt.name),Yt=ft._f&&hasPromiseValidation(ft._f);Yt&&S.validatingFields&&M([ct],!0);const or=await validateField(ft,g.disabled,d,E,e.shouldUseNativeValidation&&!at,zt);if(Yt&&S.validatingFields&&M([ct]),or[dt.name]&&(Qe.valid=!1,at))break;!at&&(get(or,dt.name)?zt?updateFieldArrayRootError(n.errors,or,dt.name):set(n.errors,dt.name,or[dt.name]):unset(n.errors,dt.name))}!isEmptyObject$1(yt)&&await se(yt,at,Qe)}}return Qe.valid},ge=()=>{for(const Ke of g.unMount){const at=get(o,Ke);at&&(at._f.refs?at._f.refs.every(Qe=>!live(Qe)):!live(at._f.ref))&&Xe(Ke)}g.unMount=new Set},oe=(Ke,at)=>!e.disabled&&(Ke&&at&&set(d,Ke,at),!deepEqual$1(qe(),l)),Ae=(Ke,at,Qe)=>generateWatchOutput(Ke,g,{...f.mount?d:isUndefined(at)?l:isString(Ke)?{[Ke]:at}:at},Qe,at),je=Ke=>compact(get(f.mount?d:l,Ke,e.shouldUnregister?get(l,Ke,[]):[])),Ne=(Ke,at,Qe={})=>{const ct=get(o,Ke);let ft=at;if(ct){const dt=ct._f;dt&&(!dt.disabled&&set(d,Ke,getFieldValueAs(at,dt)),ft=isHTMLElement(dt.ref)&&isNullOrUndefined(at)?"":at,isMultipleSelect(dt.ref)?[...dt.ref.options].forEach(yt=>yt.selected=ft.includes(yt.value)):dt.refs?isCheckBoxInput(dt.ref)?dt.refs.forEach(yt=>{(!yt.defaultChecked||!yt.disabled)&&(Array.isArray(ft)?yt.checked=!!ft.find(zt=>zt===yt.value):yt.checked=ft===yt.value||!!ft)}):dt.refs.forEach(yt=>yt.checked=yt.value===ft):isFileInput(dt.ref)?dt.ref.value="":(dt.ref.value=ft,dt.ref.type||C.state.next({name:Ke,values:cloneObject(d)})))}(Qe.shouldDirty||Qe.shouldTouch)&&F(Ke,ft,Qe.shouldTouch,Qe.shouldDirty,!0),Qe.shouldValidate&&Be(Ke)},Oe=(Ke,at,Qe)=>{for(const ct in at){if(!at.hasOwnProperty(ct))return;const ft=at[ct],dt=Ke+"."+ct,yt=get(o,dt);(g.array.has(Ke)||isObject(ft)||yt&&!yt._f)&&!isDateObject(ft)?Oe(dt,ft,Qe):Ne(dt,ft,Qe)}},Fe=(Ke,at,Qe={})=>{const ct=get(o,Ke),ft=g.array.has(Ke),dt=cloneObject(at);set(d,Ke,dt),ft?(C.array.next({name:Ke,values:cloneObject(d)}),(S.isDirty||S.dirtyFields||R.isDirty||R.dirtyFields)&&Qe.shouldDirty&&C.state.next({name:Ke,dirtyFields:getDirtyFields(l,d),isDirty:oe(Ke,dt)})):ct&&!ct._f&&!isNullOrUndefined(dt)?Oe(Ke,dt,Qe):Ne(Ke,dt,Qe),isWatched(Ke,g)&&C.state.next({...n}),C.state.next({name:f.mount?Ke:void 0,values:cloneObject(d)})},ze=async Ke=>{f.mount=!0;const at=Ke.target;let Qe=at.name,ct=!0;const ft=get(o,Qe),dt=Yt=>{ct=Number.isNaN(Yt)||isDateObject(Yt)&&isNaN(Yt.getTime())||deepEqual$1(Yt,get(d,Qe,Yt))},yt=getValidationModes(e.mode),zt=getValidationModes(e.reValidateMode);if(ft){let Yt,or;const dr=at.type?getFieldValue(ft._f):getEventValue(Ke),mt=Ke.type===EVENTS.BLUR||Ke.type===EVENTS.FOCUS_OUT,Sr=!hasValidation(ft._f)&&!e.resolver&&!get(n.errors,Qe)&&!ft._f.deps||skipValidation(mt,get(n.touchedFields,Qe),n.isSubmitted,zt,yt),Rt=isWatched(Qe,g,mt);set(d,Qe,dr),mt?(ft._f.onBlur&&ft._f.onBlur(Ke),b&&b(0)):ft._f.onChange&&ft._f.onChange(Ke);const Zt=F(Qe,dr,mt),Kt=!isEmptyObject$1(Zt)||Rt;if(!mt&&C.state.next({name:Qe,type:Ke.type,values:cloneObject(d)}),Sr)return(S.isValid||R.isValid)&&(e.mode==="onBlur"?mt&&I():mt||I()),Kt&&C.state.next({name:Qe,...Rt?{}:Zt});if(!mt&&Rt&&C.state.next({...n}),e.resolver){const{errors:nr}=await te([Qe]);if(dt(dr),ct){const ur=schemaErrorLookup(n.errors,o,Qe),Nr=schemaErrorLookup(nr,o,ur.name||Qe);Yt=Nr.error,Qe=Nr.name,or=isEmptyObject$1(nr)}}else M([Qe],!0),Yt=(await validateField(ft,g.disabled,d,E,e.shouldUseNativeValidation))[Qe],M([Qe]),dt(dr),ct&&(Yt?or=!1:(S.isValid||R.isValid)&&(or=await se(o,!0)));ct&&(ft._f.deps&&Be(ft._f.deps),V(Qe,or,Yt,Zt))}},$e=(Ke,at)=>{if(get(n.errors,at)&&Ke.focus)return Ke.focus(),1},Be=async(Ke,at={})=>{let Qe,ct;const ft=convertToArrayPayload(Ke);if(e.resolver){const dt=await ne(isUndefined(Ke)?Ke:ft);Qe=isEmptyObject$1(dt),ct=Ke?!ft.some(yt=>get(dt,yt)):Qe}else Ke?(ct=(await Promise.all(ft.map(async dt=>{const yt=get(o,dt);return await se(yt&&yt._f?{[dt]:yt}:yt)}))).every(Boolean),!(!ct&&!n.isValid)&&I()):ct=Qe=await se(o);return C.state.next({...!isString(Ke)||(S.isValid||R.isValid)&&Qe!==n.isValid?{}:{name:Ke},...e.resolver||!Ke?{isValid:Qe}:{},errors:n.errors}),at.shouldFocus&&!ct&&iterateFieldsByAction(o,$e,Ke?ft:g.mount),ct},qe=Ke=>{const at={...f.mount?d:l};return isUndefined(Ke)?at:isString(Ke)?get(at,Ke):Ke.map(Qe=>get(at,Qe))},Ge=(Ke,at)=>({invalid:!!get((at||n).errors,Ke),isDirty:!!get((at||n).dirtyFields,Ke),error:get((at||n).errors,Ke),isValidating:!!get(n.validatingFields,Ke),isTouched:!!get((at||n).touchedFields,Ke)}),He=Ke=>{Ke&&convertToArrayPayload(Ke).forEach(at=>unset(n.errors,at)),C.state.next({errors:Ke?n.errors:{}})},Ze=(Ke,at,Qe)=>{const ct=(get(o,Ke,{_f:{}})._f||{}).ref,ft=get(n.errors,Ke)||{},{ref:dt,message:yt,type:zt,...Yt}=ft;set(n.errors,Ke,{...Yt,...at,ref:ct}),C.state.next({name:Ke,errors:n.errors,isValid:!1}),Qe&&Qe.shouldFocus&&ct&&ct.focus&&ct.focus()},tt=(Ke,at)=>isFunction$3(Ke)?C.state.subscribe({next:Qe=>Ke(Ae(void 0,at),Qe)}):Ae(Ke,at,!0),Ye=Ke=>C.state.subscribe({next:at=>{shouldSubscribeByName(Ke.name,at.name,Ke.exact)&&shouldRenderFormState(at,Ke.formState||S,qt,Ke.reRenderRoot)&&Ke.callback({values:{...d},...n,...at})}}).unsubscribe,rt=Ke=>(f.mount=!0,R={...R,...Ke.formState},Ye({...Ke,formState:R})),Xe=(Ke,at={})=>{for(const Qe of Ke?convertToArrayPayload(Ke):g.mount)g.mount.delete(Qe),g.array.delete(Qe),at.keepValue||(unset(o,Qe),unset(d,Qe)),!at.keepError&&unset(n.errors,Qe),!at.keepDirty&&unset(n.dirtyFields,Qe),!at.keepTouched&&unset(n.touchedFields,Qe),!at.keepIsValidating&&unset(n.validatingFields,Qe),!e.shouldUnregister&&!at.keepDefaultValue&&unset(l,Qe);C.state.next({values:cloneObject(d)}),C.state.next({...n,...at.keepDirty?{isDirty:oe()}:{}}),!at.keepIsValid&&I()},it=({disabled:Ke,name:at})=>{(isBoolean(Ke)&&f.mount||Ke||g.disabled.has(at))&&(Ke?g.disabled.add(at):g.disabled.delete(at))},et=(Ke,at={})=>{let Qe=get(o,Ke);const ct=isBoolean(at.disabled)||isBoolean(e.disabled);return set(o,Ke,{...Qe||{},_f:{...Qe&&Qe._f?Qe._f:{ref:{name:Ke}},name:Ke,mount:!0,...at}}),g.mount.add(Ke),Qe?it({disabled:isBoolean(at.disabled)?at.disabled:e.disabled,name:Ke}):Q(Ke,!0,at.value),{...ct?{disabled:at.disabled||e.disabled}:{},...e.progressive?{required:!!at.required,min:getRuleValue(at.min),max:getRuleValue(at.max),minLength:getRuleValue(at.minLength),maxLength:getRuleValue(at.maxLength),pattern:getRuleValue(at.pattern)}:{},name:Ke,onChange:ze,onBlur:ze,ref:ft=>{if(ft){et(Ke,at),Qe=get(o,Ke);const dt=isUndefined(ft.value)&&ft.querySelectorAll&&ft.querySelectorAll("input,select,textarea")[0]||ft,yt=isRadioOrCheckbox(dt),zt=Qe._f.refs||[];if(yt?zt.find(Yt=>Yt===dt):dt===Qe._f.ref)return;set(o,Ke,{_f:{...Qe._f,...yt?{refs:[...zt.filter(live),dt,...Array.isArray(get(l,Ke))?[{}]:[]],ref:{type:dt.type,name:Ke}}:{ref:dt}}}),Q(Ke,!1,void 0,dt)}else Qe=get(o,Ke,{}),Qe._f&&(Qe._f.mount=!1),(e.shouldUnregister||at.shouldUnregister)&&!(isNameInFieldArray(g.array,Ke)&&f.action)&&g.unMount.add(Ke)}}},st=()=>e.shouldFocusError&&iterateFieldsByAction(o,$e,g.mount),ot=Ke=>{isBoolean(Ke)&&(C.state.next({disabled:Ke}),iterateFieldsByAction(o,(at,Qe)=>{const ct=get(o,Qe);ct&&(at.disabled=ct._f.disabled||Ke,Array.isArray(ct._f.refs)&&ct._f.refs.forEach(ft=>{ft.disabled=ct._f.disabled||Ke}))},0,!1))},Ue=(Ke,at)=>async Qe=>{let ct;Qe&&(Qe.preventDefault&&Qe.preventDefault(),Qe.persist&&Qe.persist());let ft=cloneObject(d);if(C.state.next({isSubmitting:!0}),e.resolver){const{errors:dt,values:yt}=await te();n.errors=dt,ft=yt}else await se(o);if(g.disabled.size)for(const dt of g.disabled)set(ft,dt,void 0);if(unset(n.errors,"root"),isEmptyObject$1(n.errors)){C.state.next({errors:{}});try{await Ke(ft,Qe)}catch(dt){ct=dt}}else at&&await at({...n.errors},Qe),st(),setTimeout(st);if(C.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:isEmptyObject$1(n.errors)&&!ct,submitCount:n.submitCount+1,errors:n.errors}),ct)throw ct},Ct=(Ke,at={})=>{get(o,Ke)&&(isUndefined(at.defaultValue)?Fe(Ke,cloneObject(get(l,Ke))):(Fe(Ke,at.defaultValue),set(l,Ke,cloneObject(at.defaultValue))),at.keepTouched||unset(n.touchedFields,Ke),at.keepDirty||(unset(n.dirtyFields,Ke),n.isDirty=at.defaultValue?oe(Ke,cloneObject(get(l,Ke))):oe()),at.keepError||(unset(n.errors,Ke),S.isValid&&I()),C.state.next({...n}))},Je=(Ke,at={})=>{const Qe=Ke?cloneObject(Ke):l,ct=cloneObject(Qe),ft=isEmptyObject$1(Ke),dt=ft?l:ct;if(at.keepDefaultValues||(l=Qe),!at.keepValues){if(at.keepDirtyValues){const yt=new Set([...g.mount,...Object.keys(getDirtyFields(l,d))]);for(const zt of Array.from(yt))get(n.dirtyFields,zt)?set(dt,zt,get(d,zt)):Fe(zt,get(dt,zt))}else{if(isWeb&&isUndefined(Ke))for(const yt of g.mount){const zt=get(o,yt);if(zt&&zt._f){const Yt=Array.isArray(zt._f.refs)?zt._f.refs[0]:zt._f.ref;if(isHTMLElement(Yt)){const or=Yt.closest("form");if(or){or.reset();break}}}}for(const yt of g.mount)Fe(yt,get(dt,yt))}d=cloneObject(dt),C.array.next({values:{...dt}}),C.state.next({values:{...dt}})}g={mount:at.keepDirtyValues?g.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},f.mount=!S.isValid||!!at.keepIsValid||!!at.keepDirtyValues,f.watch=!!e.shouldUnregister,C.state.next({submitCount:at.keepSubmitCount?n.submitCount:0,isDirty:ft?!1:at.keepDirty?n.isDirty:!!(at.keepDefaultValues&&!deepEqual$1(Ke,l)),isSubmitted:at.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ft?{}:at.keepDirtyValues?at.keepDefaultValues&&d?getDirtyFields(l,d):n.dirtyFields:at.keepDefaultValues&&Ke?getDirtyFields(l,Ke):at.keepDirty?n.dirtyFields:{},touchedFields:at.keepTouched?n.touchedFields:{},errors:at.keepErrors?n.errors:{},isSubmitSuccessful:at.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},pt=(Ke,at)=>Je(isFunction$3(Ke)?Ke(d):Ke,at),Mt=(Ke,at={})=>{const Qe=get(o,Ke),ct=Qe&&Qe._f;if(ct){const ft=ct.refs?ct.refs[0]:ct.ref;ft.focus&&(ft.focus(),at.shouldSelect&&isFunction$3(ft.select)&&ft.select())}},qt=Ke=>{n={...n,...Ke}},Ft={control:{register:et,unregister:Xe,getFieldState:Ge,handleSubmit:Ue,setError:Ze,_subscribe:Ye,_runSchema:te,_focusError:st,_getWatch:Ae,_getDirty:oe,_setValid:I,_setFieldArray:j,_setDisabledField:it,_setErrors:z,_getFieldArray:je,_reset:Je,_resetDefaultValues:()=>isFunction$3(e.defaultValues)&&e.defaultValues().then(Ke=>{pt(Ke,e.resetOptions),C.state.next({isLoading:!1})}),_removeUnmounted:ge,_disableForm:ot,_subjects:C,_proxyFormState:S,get _fields(){return o},get _formValues(){return d},get _state(){return f},set _state(Ke){f=Ke},get _defaultValues(){return l},get _names(){return g},set _names(Ke){g=Ke},get _formState(){return n},get _options(){return e},set _options(Ke){e={...e,...Ke}}},subscribe:rt,trigger:Be,register:et,handleSubmit:Ue,watch:tt,setValue:Fe,getValues:qe,reset:pt,resetField:Ct,clearErrors:He,unregister:Xe,setError:Ze,setFocus:Mt,getFieldState:Ge};return{...Ft,formControl:Ft}}function useForm(t={}){const e=React.useRef(void 0),n=React.useRef(void 0),[o,l]=React.useState({isDirty:!1,isValidating:!1,isLoading:isFunction$3(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1,isReady:!1,defaultValues:isFunction$3(t.defaultValues)?void 0:t.defaultValues});e.current||(e.current={...t.formControl?t.formControl:createFormControl(t),formState:o},t.formControl&&t.defaultValues&&!isFunction$3(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions));const d=e.current.control;return d._options=t,useIsomorphicLayoutEffect$1(()=>{const f=d._subscribe({formState:d._proxyFormState,callback:()=>l({...d._formState}),reRenderRoot:!0});return l(g=>({...g,isReady:!0})),d._formState.isReady=!0,f},[d]),React.useEffect(()=>d._disableForm(t.disabled),[d,t.disabled]),React.useEffect(()=>{t.mode&&(d._options.mode=t.mode),t.reValidateMode&&(d._options.reValidateMode=t.reValidateMode)},[d,t.mode,t.reValidateMode]),React.useEffect(()=>{t.errors&&(d._setErrors(t.errors),d._focusError())},[d,t.errors]),React.useEffect(()=>{t.shouldUnregister&&d._subjects.state.next({values:d._getWatch()})},[d,t.shouldUnregister]),React.useEffect(()=>{if(d._proxyFormState.isDirty){const f=d._getDirty();f!==o.isDirty&&d._subjects.state.next({isDirty:f})}},[d,o.isDirty]),React.useEffect(()=>{t.values&&!deepEqual$1(t.values,n.current)?(d._reset(t.values,d._options.resetOptions),n.current=t.values,l(f=>({...f}))):d._resetDefaultValues()},[d,t.values]),React.useEffect(()=>{d._state.mount||(d._setValid(),d._state.mount=!0),d._state.watch&&(d._state.watch=!1,d._subjects.state.next({...d._formState})),d._removeUnmounted()}),e.current.formState=getProxyFormState(o,d),e.current}var defaultErrorHandler=function(t){process.env.NODE_ENV!=="production"&&console.error(t)},defaultWarnHandler=function(t){process.env.NODE_ENV!=="production"&&console.warn(t)},DEFAULT_INTL_CONFIG={formats:{},messages:{},timeZone:void 0,defaultLocale:"en",defaultFormats:{},fallbackOnEmptyString:!0,onError:defaultErrorHandler,onWarn:defaultWarnHandler};function invariant(t,e,n){if(n===void 0&&(n=Error),!t)throw new n(e)}function invariantIntlContext(t){invariant(t,"[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.")}__assign$1(__assign$1({},DEFAULT_INTL_CONFIG),{textComponent:React__namespace.Fragment});var reactIs={exports:{}},reactIs_production_min={};/** @license React v16.13.1
1054
1054
  * react-is.production.min.js
1055
1055
  *
1056
1056
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -1069,7 +1069,7 @@ Please report this to https://github.com/markedjs/marked.`,t){const o="<p>An err
1069
1069
  - less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
1070
1070
  - \`null\` or \`undefined\` if the progress is indeterminate.
1071
1071
 
1072
- Defaulting to \`null\`.`}var Root=Progress$1,Indicator=ProgressIndicator;const Progress=React__namespace.forwardRef(({className:t,value:e,...n},o)=>jsxRuntime.jsx(Root,{ref:o,className:cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",t),...n,children:jsxRuntime.jsx(Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(e||0)}%)`}})}));Progress.displayName=Root.displayName;function ManufacturerInventoryFinanceCard({manufacturer:t,isLoading:e}){const{data:n,isLoading:o,isFetching:l}=useGetV4ManufacturerByRouteManufacturerIdInventoryValueQuery({routeManufacturerId:(t==null?void 0:t.ManufacturerId)??""},{skip:!(t!=null&&t.ManufacturerId)}),d=(t==null?void 0:t.DefaultMaxInventoryValue)??0,f=(n||[]).reduce((_,S)=>_+(S.InventoryValue||0),0),g=d-f,b=Math.round(f/d*100);return e||o||l?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(DollarSign,{className:"h-5 w-5 text-muted-foreground"}),"Inventory Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current inventory financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Max Allowance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(d)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Current Funds"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(f)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available Funds"}),jsxRuntime.jsx("span",{className:`font-bold ${g>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(g)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Budget Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[b,"%"]}),b>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:b>80?"High usage alert":"Budget usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:b,className:"h-2"})]})]})]})}function ManufacturerCreditFinanceCard({manufacturer:t,isLoading:e}){const n=(t==null?void 0:t.CreditLimit)??0,o=(t==null?void 0:t.OutstandingBalance)??0,l=n-o,d=Math.round(o/n*100);return e?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(CreditCard,{className:"h-5 w-5 text-muted-foreground"}),"Credit Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current credit financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Limit"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(n)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Outstanding Balance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(o)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available Credit"}),jsxRuntime.jsx("span",{className:`font-bold ${l>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(l)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[d,"%"]}),d>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:d>80?"High credit usage alert":"Credit usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:d,className:"h-2"})]})]})]})}function ManufacturerOverviewPage({applicationId:t,readonly:e,withReports:n,manufacturer:o,userEmail:l}){var A;const{data:d,isLoading:f,isError:g}=useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:t,withSpecification:!0},{skip:!!o}),[b,_]=React.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),S=React.useCallback(()=>e?!1:b.publicInfo.hasUnsavedChanges||b.qualifications.hasUnsavedChanges||b.billingInfo.hasUnsavedChanges,[e,b]),R=React.useCallback((I,M)=>{_(j=>{var q;return((q=j[I])==null?void 0:q.hasUnsavedChanges)!==M.hasUnsavedChanges?(console.log(`Updating form state for ${I}:`,M.hasUnsavedChanges),{...j,[I]:M}):j})},[]),{NavigationGuardDialog:C}=useRouterNavigationGuard(S),E=o??d;return jsxRuntime.jsxs("div",{className:"@container",children:[g?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your manufacturer information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:E==null?void 0:E.FiscalYearMonthStart,salesData:E==null?void 0:E.SalesData,isLoading:f}),jsxRuntime.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChart,{salesData:(E==null?void 0:E.SalesStatistics)??[],isLoading:f}),jsxRuntime.jsx(ManufacturerResellerOrdersSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",activeOrders:(E==null?void 0:E.ActiveOrderDetails)??void 0,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerInventoryFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerCreditFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerReorderingCard,{manufacturer:E??{},onSave:()=>{},loading:f,readonly:!0}),n&&jsxRuntime.jsx(ManufacturerPublicInfoSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("publicInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(OpenToWorkSection,{manufacturer:E,readonly:e,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerBillingInfoSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("billingInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(ManufacturerQualificationsSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("qualifications",{hasUnsavedChanges:I})})]}),n&&jsxRuntime.jsx(ManufacturerReportsSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",userEmail:l,isLoading:f}),(E==null?void 0:E.ManufacturerId)&&!((A=E.SalesStatistics)!=null&&A.length)&&jsxRuntime.jsx(AssistantChat,{userId:t,userName:l??"Partner",initialPrompt:`Please give me an extended report on Manufacturer #${E==null?void 0:E.ManufacturerId}. What types of product do they sell? I'd like to know if it would make sense for me to start reselling their products.`})]}),jsxRuntime.jsx(C,{})]})}function ManufacturerCategories({categories:t,activeCategory:e,onSelectCategory:n}){return jsxRuntime.jsx("div",{className:"grid",children:jsxRuntime.jsx("div",{className:"flex overflow-x-auto small-scrollbar pb-4",children:jsxRuntime.jsx("div",{className:"flex gap-2",children:t.map(o=>jsxRuntime.jsxs(Button,{onClick:()=>n(o.CategoryCode??""),variant:e===o.CategoryCode?"default":"outline",size:"sm",className:"px-3 py-1.5 text-xs whitespace-nowrap rounded-full",children:[o.CategoryName??"Undefined",o.QualificationRequired&&jsxRuntime.jsx(ShieldCheck,{className:`ml-1 w-5 h-5 ${e!==o.CategoryCode?"text-red-500":""}`})]},o.CategoryCode))})})})}function ManufacturerProducts({applicationId:t,manufacturer:e,shopifyHostName:n}){var M,j,q,z;const[o]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[l,d]=React.useState(((j=(M=e.Categories)==null?void 0:M[0])==null?void 0:j.CategoryCode)||""),[f,g]=React.useState(!1),[b,_]=React.useState(!1),{toast:S}=useToast(),{data:R,isLoading:C,isFetching:E}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:t,manufacturerId:e.ManufacturerId,categoryCode:l??""},{skip:!e.ManufacturerId||!l}),A=async()=>{try{g(!0),_(!1),await o({routeResellerId:t,manufacturerId:e.ManufacturerId??"",categoryCode:l,shopifyHostName:n}).unwrap()&&S({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(Q){console.error("Error syncing to Shopify:",Q),S({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{g(!1)}},I=()=>{var Q,F;return((F=(Q=e.Categories)==null?void 0:Q.find(V=>V.CategoryCode===l))==null?void 0:F.CategoryName)||l};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ManufacturerCategories,{categories:e.Categories||[],activeCategory:l,onSelectCategory:d}),n&&((q=e.Categories)==null?void 0:q.findIndex(Q=>Q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:b,onOpenChange:_,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 mb-4",disabled:f,children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Category to Shopify"]})})}),jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the category "',I(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:A,disabled:f,children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4 mb-4",children:C||E?Array.from({length:4}).map((Q,F)=>jsxRuntime.jsx(ProductCard,{},F)):R!=null&&R.Products&&(R==null?void 0:R.Products.length)>0?(z=[...R.Products].sort((Q,F)=>{const V=Q.OverallPercentileRank??0;return(F.OverallPercentileRank??0)-V}))==null?void 0:z.map(Q=>jsxRuntime.jsx(ProductCard,{applicationId:t,product:Q,viewProductLink:`/${t}/Product/${Q.RandmarSKU}`,shopifyHostname:n},Q.RandmarSKU)):jsxRuntime.jsxs(Alert,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Warning"}),jsxRuntime.jsx(AlertDescription,{children:"No products found for this manufacturer category."})]})})]})}function PartnerRelationshipPage({applicationId:t,partnerId:e,userEmail:n,shopifyHostName:o,isSuperAdmin:l}){var I,M,j;const{data:d,isLoading:f}=useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({routeApplicationId:t,partnerId:e,withSpecification:!0}),{toast:g}=useToast(),[b]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[_,S]=React.useState(!1),[R,C]=React.useState(!1),E=async()=>{try{S(!0),C(!1),await b({routeResellerId:t??"",manufacturerId:e??"",shopifyHostName:o}).unwrap()&&g({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(q){console.error("Error syncing to Shopify:",q),g({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{S(!1)}},A=()=>d!=null&&d.Reseller?"reseller-overview":d!=null&&d.Manufacturer?"manufacturer-overview":"";return jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 @2xl:grid-cols-2",children:[jsxRuntime.jsx(PartnerCard,{account:d,loading:f,withAbout:!0,withVoice:!1,action:" "}),jsxRuntime.jsxs("div",{className:"grid gap-4",children:[((d==null?void 0:d.Manufacturer)||f)&&jsxRuntime.jsx(ManufacturerCard,{manufacturer:d==null?void 0:d.Manufacturer,loading:f,mainAction:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(ManufacturerGetStartedButton,{applicationId:t,manufacturer:d==null?void 0:d.Manufacturer}),o&&((M=(I=d==null?void 0:d.Manufacturer)==null?void 0:I.Categories)==null?void 0:M.findIndex(q=>q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:R,onOpenChange:C,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 ml-2",disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Manufacturer to Shopify"]})})}),jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the manufacturer "',(j=d==null?void 0:d.Manufacturer)==null?void 0:j.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:E,disabled:_,children:_?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(ResellerCard,{reseller:d==null?void 0:d.Reseller,loading:f})]})]}),((d==null?void 0:d.Reseller)||(d==null?void 0:d.Manufacturer))&&!f&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4",children:jsxRuntime.jsxs(Tabs,{defaultValue:A(),className:"w-full",children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsTrigger,{value:"reseller-overview",className:"reseller-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Reseller Overview"}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"manufacturer-overview",className:"manufacturer-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Manufacturer Overview"}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"products",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Products"})]}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsContent,{value:"reseller-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ResellerOverview,{readonly:!0,appID:d.ApplicationId||"",reseller:d==null?void 0:d.Reseller,userEmail:n,isSuperAdmin:l,withoutReports:!0})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"manufacturer-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerOverviewPage,{readonly:!0,manufacturer:d==null?void 0:d.Manufacturer,applicationId:t,userEmail:n})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"products",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerProducts,{applicationId:t,manufacturer:d.Manufacturer,shopifyHostName:o})})})]})}),f&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4 mt-4 flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})})]})}const PublicInfo=({reseller:t,appID:e,isLoading:n,readonly:o,onUnsavedChanges:l})=>{const{toast:d}=useToast(),[f]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),[g,b]=React.useState({}),_=React.useMemo(()=>({publicEmail:t.PublicEmail??"",contactName:t.ContactName??"",phone:t.Phone??"",website:t.Website??""}),[t]),{register:S,handleSubmit:R,reset:C,watch:E,formState:{errors:A,isSubmitting:I}}=useForm({defaultValues:_}),M=E(),j=React.useCallback(()=>g?JSON.stringify(M)!==JSON.stringify(g):!1,[M,g]);React.useEffect(()=>{l&&l(j())},[j,l]),React.useEffect(()=>{t&&Object.keys(t).length>0&&(C(_),b(_))},[t,C,_]);const q=async Q=>{let F=!0,V=!1;const te=Object.keys(Q).map(ne=>({key:ne,keyApi:ne.charAt(0).toUpperCase()+ne.slice(1)}));for(const ne of te){const se=Q[ne.key],ge=t[ne.keyApi];if(se!==ge&&se!==void 0){V=!0;try{await f({applicationId:e,fieldName:ne.keyApi,newValue:String(se)}).unwrap()||(F=!1)}catch(oe){console.error(`Error updating ${ne.keyApi}:`,oe),F=!1}}}F&&V?(d({title:"Public info",description:"Information updated successfully",variant:"success"}),b({...Q}),l&&l(!1)):F||d({title:"Updation error",description:"Failed to update",variant:"destructive"})},z=Q=>!Q||Q.trim()==="";return n?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Public Information"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})})]})})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{className:"text-1xl font-bold",children:["Public Information ",o?"(read only)":""]})}),jsxRuntime.jsxs(CardContent,{children:[(z(E("contactName"))||z(E("publicEmail"))||z(E("website"))||z(E("phone")))&&jsxRuntime.jsxs(Alert,{variant:"destructive",className:"mb-6",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Missing information"}),jsxRuntime.jsx(AlertDescription,{children:"All fields are required to get started at working with Manufacturers."})]}),jsxRuntime.jsxs("form",{onSubmit:R(q),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"contactName",children:"Main Representative *"}),jsxRuntime.jsx(Input,{id:"contactName",placeholder:"John Doe",readOnly:o,...S("contactName",{}),className:A.contactName||z(E("contactName"))?"input-error-indicator":""}),A.contactName&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.contactName.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"publicEmail",children:"Public Email *"}),jsxRuntime.jsx(Input,{id:"publicEmail",placeholder:"contact@company.com",readOnly:o,...S("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:A.publicEmail||z(E("publicEmail"))?"input-error-indicator":""}),A.publicEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.publicEmail.message})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),jsxRuntime.jsx(Input,{id:"website",placeholder:"https://company.com",readOnly:o,...S("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.website||z(E("website"))?"input-error-indicator":""}),A.website&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.website.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone Number *"}),jsxRuntime.jsx(Input,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:o,...S("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.phone||z(E("phone"))?"input-error-indicator":""}),A.phone&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.phone.message})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I||o,className:o?"hidden":"",children:I?"Saving...":"Save"})})]})]})]})};function BillingCard({appID:t,reseller:e,isLoading:n,withoutReports:o}){const{Statement:l,CreditLimit:d}=e,f=[{label:"0 - 30 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over0)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:Calendar},{label:"31 - 45 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over30)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarDays},{label:"45+ Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over45)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarRange},{label:"Total",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Total)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:DollarSign},{label:"Credit Limit",value:jsxRuntime.jsx(FormattedNumber,{value:d||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CreditCard}],g=()=>{const _=`https://dashboard.randmar.io/${t}/PayInvoice`;window.open(_,"_blank","noopener,noreferrer")};if(n)return jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(Skeleton,{className:"h-6 w-36"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:[1,2,3].map(_=>jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]},_))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:[1,2].map(_=>jsxRuntime.jsx("div",{className:_===2?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]})},_))})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-28 mt-6"})})]})]});const b=!o;return jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Billing Overview"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:f.slice(0,3).map((_,S)=>jsxRuntime.jsx(BillingItem,{icon:_.icon,label:_.label,value:_.value},S))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:f.slice(3).map((_,S)=>jsxRuntime.jsx("div",{className:S===1?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsx(BillingItem,{icon:_.icon,label:_.label,value:_.value})},S))})]}),b&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{className:"mt-6",onClick:g,children:"Pay Invoices"})})]})]})}function BillingItem({icon:t,label:e,value:n}){return jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(t,{className:"size-4 text-muted-foreground"}),jsxRuntime.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:e})]}),jsxRuntime.jsx("span",{className:"text-base font-semibold ms-auto",children:n})]})}function ChangePricingTierModal({open:t,setOpen:e,tier:n,onTierChange:o,isLoading:l}){const d=()=>{e(!1)};return jsxRuntime.jsx(Dialog,{open:t,onOpenChange:e,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsx(DialogTitle,{children:"Change Pricing Tier"})}),jsxRuntime.jsxs("div",{className:"grid gap-1.5 py-2",children:[jsxRuntime.jsxs("p",{className:"text-lg text-muted-foreground",children:["Requested Pricing Tier: ",jsxRuntime.jsx("span",{className:"font-bold",children:n})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If your account qualifies, your pricing will update immediately."}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If not, we'll review your request and notify you of the decision."})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:d,disabled:l,children:"Cancel"}),jsxRuntime.jsx(Button,{onClick:o,disabled:l,children:l?"Loading...":`Apply for ${n}`})]})]})})}const getPricingText=t=>t===1?"The Best":t===2?"Fixed 12.5% GP on all items":t===3?"Advantageous":t===4?"Buying Group":t===5?"Cost":t,getShippingText=t=>t==="A"?"Free or Custom":t==="B"?"Fixed $10 anywhere":t==="C"?`Free shipping on $150+ orders to your location,
1072
+ Defaulting to \`null\`.`}var Root=Progress$1,Indicator=ProgressIndicator;const Progress=React__namespace.forwardRef(({className:t,value:e,...n},o)=>jsxRuntime.jsx(Root,{ref:o,className:cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",t),...n,children:jsxRuntime.jsx(Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(e||0)}%)`}})}));Progress.displayName=Root.displayName;function ManufacturerInventoryFinanceCard({manufacturer:t,isLoading:e}){const{data:n,isLoading:o,isFetching:l}=useGetV4ManufacturerByRouteManufacturerIdInventoryValueQuery({routeManufacturerId:(t==null?void 0:t.ManufacturerId)??""},{skip:!(t!=null&&t.ManufacturerId)}),d=(t==null?void 0:t.DefaultMaxInventoryValue)??0,f=(n||[]).reduce((_,S)=>_+(S.InventoryValue||0),0),g=d-f,b=Math.round(f/d*100);return e||o||l?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(DollarSign,{className:"h-5 w-5 text-muted-foreground"}),"Inventory Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current inventory financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Max Allowance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(d)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Current Funds"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(f)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available Funds"}),jsxRuntime.jsx("span",{className:`font-bold ${g>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(g)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Budget Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[b,"%"]}),b>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:b>80?"High usage alert":"Budget usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:b,className:"h-2"})]})]})]})}function ManufacturerCreditFinanceCard({manufacturer:t,isLoading:e}){const n=(t==null?void 0:t.CreditLimit)??0,o=(t==null?void 0:t.OutstandingBalance)??0,l=n-o,d=Math.round(o/n*100);return e?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(Skeleton,{className:"h-7 w-3/4"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/2 mt-2"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/4"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-1/3"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-16"})]}),jsxRuntime.jsx(Skeleton,{className:"h-2 w-full"})]})]})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsxs(CardTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx(CreditCard,{className:"h-5 w-5 text-muted-foreground"}),"Credit Finance"]}),jsxRuntime.jsx(CardDescription,{children:"Current credit financial status"})]}),jsxRuntime.jsxs(CardContent,{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Limit"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(n)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Outstanding Balance"}),jsxRuntime.jsx("span",{className:"font-bold",children:formatMoney(o)})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Available Credit"}),jsxRuntime.jsx("span",{className:`font-bold ${l>=0?"text-emerald-600 dark:text-emerald-500":"text-red-600 dark:text-red-500"}`,children:formatMoney(l)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium",children:"Credit Usage"}),jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[d,"%"]}),d>80&&jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4 text-amber-500"})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:d>80?"High credit usage alert":"Credit usage"})})]})})]}),jsxRuntime.jsx(Progress,{value:d,className:"h-2"})]})]})]})}function ManufacturerOverviewPage({applicationId:t,readonly:e,withReports:n,manufacturer:o,userEmail:l}){var A;const{data:d,isLoading:f,isError:g}=useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:t,withSpecification:!0},{skip:!!o}),[b,_]=React.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),S=React.useCallback(()=>e?!1:b.publicInfo.hasUnsavedChanges||b.qualifications.hasUnsavedChanges||b.billingInfo.hasUnsavedChanges,[e,b]),R=React.useCallback((I,M)=>{_(j=>{var q;return((q=j[I])==null?void 0:q.hasUnsavedChanges)!==M.hasUnsavedChanges?(console.log(`Updating form state for ${I}:`,M.hasUnsavedChanges),{...j,[I]:M}):j})},[]),{NavigationGuardDialog:C}=useRouterNavigationGuard(S),E=o??d;return jsxRuntime.jsxs("div",{className:"@container",children:[g?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your manufacturer information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:E==null?void 0:E.FiscalYearMonthStart,salesData:E==null?void 0:E.SalesData,isLoading:f}),jsxRuntime.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChart,{salesData:(E==null?void 0:E.SalesStatistics)??[],isLoading:f}),jsxRuntime.jsx(ManufacturerResellerOrdersSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",activeOrders:(E==null?void 0:E.ActiveOrderDetails)??void 0,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerInventoryFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerCreditFinanceCard,{manufacturer:E,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerReorderingCard,{manufacturer:E??{},onSave:()=>{},loading:f,readonly:!0}),n&&jsxRuntime.jsx(ManufacturerPublicInfoSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("publicInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(OpenToWorkSection,{manufacturer:E,readonly:e,isLoading:f}),n&&jsxRuntime.jsx(ManufacturerBillingInfoSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("billingInfo",{hasUnsavedChanges:I})}),n&&jsxRuntime.jsx(ManufacturerQualificationsSection,{manufacturer:E,readonly:e,isLoading:f,onUnsavedChanges:I=>R("qualifications",{hasUnsavedChanges:I})})]}),n&&jsxRuntime.jsx(ManufacturerReportsSection,{manufacturerId:(E==null?void 0:E.ManufacturerId)??"",userEmail:l,isLoading:f}),(E==null?void 0:E.ManufacturerId)&&!((A=E.SalesStatistics)!=null&&A.length)&&jsxRuntime.jsx(AssistantChat,{userId:t,userName:l??"Partner",initialPrompt:`Please give me an extended report on Manufacturer #${E==null?void 0:E.ManufacturerId}. What types of product do they sell? I'd like to know if it would make sense for me to start reselling their products.`})]}),jsxRuntime.jsx(C,{})]})}function ManufacturerCategories({categories:t,activeCategory:e,onSelectCategory:n}){return jsxRuntime.jsx("div",{className:"grid",children:jsxRuntime.jsx("div",{className:"flex overflow-x-auto small-scrollbar pb-4",children:jsxRuntime.jsx("div",{className:"flex gap-2",children:t.map(o=>jsxRuntime.jsxs(Button,{onClick:()=>n(o.CategoryCode??""),variant:e===o.CategoryCode?"default":"outline",size:"sm",className:"px-3 py-1.5 text-xs whitespace-nowrap rounded-full",children:[o.CategoryName??"Undefined",o.QualificationRequired&&jsxRuntime.jsx(ShieldCheck,{className:`ml-1 w-5 h-5 ${e!==o.CategoryCode?"text-red-500":""}`})]},o.CategoryCode))})})})}function ManufacturerProducts({applicationId:t,manufacturer:e,shopifyHostName:n}){var M,j,q,z;const[o]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[l,d]=React.useState(((j=(M=e.Categories)==null?void 0:M[0])==null?void 0:j.CategoryCode)||""),[f,g]=React.useState(!1),[b,_]=React.useState(!1),{toast:S}=useToast(),{data:R,isLoading:C,isFetching:E}=useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:t,manufacturerId:e.ManufacturerId,categoryCode:l??""},{skip:!e.ManufacturerId||!l}),A=async()=>{try{g(!0),_(!1),await o({routeResellerId:t,manufacturerId:e.ManufacturerId??"",categoryCode:l,shopifyHostName:n}).unwrap()&&S({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(Q){console.error("Error syncing to Shopify:",Q),S({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{g(!1)}},I=()=>{var Q,F;return((F=(Q=e.Categories)==null?void 0:Q.find(V=>V.CategoryCode===l))==null?void 0:F.CategoryName)||l};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ManufacturerCategories,{categories:e.Categories||[],activeCategory:l,onSelectCategory:d}),n&&((q=e.Categories)==null?void 0:q.findIndex(Q=>Q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:b,onOpenChange:_,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 mb-4",disabled:f,children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Category to Shopify"]})})}),jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the category "',I(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:A,disabled:f,children:f?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4 mb-4",children:C||E?Array.from({length:4}).map((Q,F)=>jsxRuntime.jsx(ProductCard,{},F)):R!=null&&R.Products&&(R==null?void 0:R.Products.length)>0?(z=[...R.Products].sort((Q,F)=>{const V=Q.OverallPercentileRank??0;return(F.OverallPercentileRank??0)-V}))==null?void 0:z.map(Q=>jsxRuntime.jsx(ProductCard,{applicationId:t,product:Q,viewProductLink:`/${t}/Product/${Q.RandmarSKU}`,shopifyHostname:n},Q.RandmarSKU)):jsxRuntime.jsxs(Alert,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Warning"}),jsxRuntime.jsx(AlertDescription,{children:"No products found for this manufacturer category."})]})})]})}function PartnerRelationshipPage({applicationId:t,partnerId:e,userEmail:n,shopifyHostName:o,isSuperAdmin:l}){var j,q,z;const{data:d,isLoading:f,isFetching:g}=useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({routeApplicationId:t,partnerId:e,withSpecification:!0}),b=f||g,{toast:_}=useToast(),[S]=usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[R,C]=React.useState(!1),[E,A]=React.useState(!1),I=async()=>{try{C(!0),A(!1),await S({routeResellerId:t??"",manufacturerId:e??"",shopifyHostName:o}).unwrap()&&_({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(Q){console.error("Error syncing to Shopify:",Q),_({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{C(!1)}},M=()=>d!=null&&d.Reseller?"reseller-overview":d!=null&&d.Manufacturer?"manufacturer-overview":"";return jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 @2xl:grid-cols-2",children:[jsxRuntime.jsx(PartnerCard,{account:d,loading:b,withAbout:!0,withVoice:!1,action:" "}),jsxRuntime.jsxs("div",{className:"grid gap-4",children:[((d==null?void 0:d.Manufacturer)||b)&&jsxRuntime.jsx(ManufacturerCard,{manufacturer:d==null?void 0:d.Manufacturer,loading:b,mainAction:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(ManufacturerGetStartedButton,{applicationId:t,manufacturer:d==null?void 0:d.Manufacturer}),o&&((q=(j=d==null?void 0:d.Manufacturer)==null?void 0:j.Categories)==null?void 0:q.findIndex(Q=>Q.AvailableToBuy))!==-1&&jsxRuntime.jsxs(Dialog,{open:E,onOpenChange:A,children:[jsxRuntime.jsx(DialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700 ml-2",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Manufacturer to Shopify"]})})}),jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Confirm Sync to Shopify"}),jsxRuntime.jsxs(DialogDescription,{children:['Are you sure you want to sync the manufacturer "',(z=d==null?void 0:d.Manufacturer)==null?void 0:z.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{className:"bg-green-600 hover:bg-green-700",onClick:I,disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(ResellerCard,{reseller:d==null?void 0:d.Reseller,loading:b})]})]}),((d==null?void 0:d.Reseller)||(d==null?void 0:d.Manufacturer))&&!b&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4",children:jsxRuntime.jsxs(Tabs,{defaultValue:M(),className:"w-full",children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsTrigger,{value:"reseller-overview",className:"reseller-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Reseller Overview"}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"manufacturer-overview",className:"manufacturer-theme relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Manufacturer Overview"}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsTrigger,{value:"products",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Products"})]}),(d==null?void 0:d.Reseller)&&jsxRuntime.jsx(TabsContent,{value:"reseller-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ResellerOverview,{readonly:!0,appID:d.ApplicationId||"",reseller:d==null?void 0:d.Reseller,userEmail:n,isSuperAdmin:l,withoutReports:!0})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"manufacturer-overview",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerOverviewPage,{readonly:!0,manufacturer:d==null?void 0:d.Manufacturer,applicationId:t,userEmail:n})})}),(d==null?void 0:d.Manufacturer)&&jsxRuntime.jsx(TabsContent,{value:"products",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ManufacturerProducts,{applicationId:t,manufacturer:d.Manufacturer,shopifyHostName:o})})})]})}),b&&jsxRuntime.jsx("div",{className:"max-w-6xl mx-auto p-4 mt-4 flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})})]})}const PublicInfo=({reseller:t,appID:e,isLoading:n,readonly:o,onUnsavedChanges:l})=>{const{toast:d}=useToast(),[f]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),[g,b]=React.useState({}),_=React.useMemo(()=>({publicEmail:t.PublicEmail??"",contactName:t.ContactName??"",phone:t.Phone??"",website:t.Website??""}),[t]),{register:S,handleSubmit:R,reset:C,watch:E,formState:{errors:A,isSubmitting:I}}=useForm({defaultValues:_}),M=E(),j=React.useCallback(()=>g?JSON.stringify(M)!==JSON.stringify(g):!1,[M,g]);React.useEffect(()=>{l&&l(j())},[j,l]),React.useEffect(()=>{t&&Object.keys(t).length>0&&(C(_),b(_))},[t,C,_]);const q=async Q=>{let F=!0,V=!1;const te=Object.keys(Q).map(ne=>({key:ne,keyApi:ne.charAt(0).toUpperCase()+ne.slice(1)}));for(const ne of te){const se=Q[ne.key],ge=t[ne.keyApi];if(se!==ge&&se!==void 0){V=!0;try{await f({applicationId:e,fieldName:ne.keyApi,newValue:String(se)}).unwrap()||(F=!1)}catch(oe){console.error(`Error updating ${ne.keyApi}:`,oe),F=!1}}}F&&V?(d({title:"Public info",description:"Information updated successfully",variant:"success"}),b({...Q}),l&&l(!1)):F||d({title:"Updation error",description:"Failed to update",variant:"destructive"})},z=Q=>!Q||Q.trim()==="";return n?jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Public Information"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-20"})})]})})]}):jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{className:"text-1xl font-bold",children:["Public Information ",o?"(read only)":""]})}),jsxRuntime.jsxs(CardContent,{children:[(z(E("contactName"))||z(E("publicEmail"))||z(E("website"))||z(E("phone")))&&jsxRuntime.jsxs(Alert,{variant:"destructive",className:"mb-6",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Missing information"}),jsxRuntime.jsx(AlertDescription,{children:"All fields are required to get started at working with Manufacturers."})]}),jsxRuntime.jsxs("form",{onSubmit:R(q),className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"contactName",children:"Main Representative *"}),jsxRuntime.jsx(Input,{id:"contactName",placeholder:"John Doe",readOnly:o,...S("contactName",{}),className:A.contactName||z(E("contactName"))?"input-error-indicator":""}),A.contactName&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.contactName.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"publicEmail",children:"Public Email *"}),jsxRuntime.jsx(Input,{id:"publicEmail",placeholder:"contact@company.com",readOnly:o,...S("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:A.publicEmail||z(E("publicEmail"))?"input-error-indicator":""}),A.publicEmail&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.publicEmail.message})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),jsxRuntime.jsx(Input,{id:"website",placeholder:"https://company.com",readOnly:o,...S("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.website||z(E("website"))?"input-error-indicator":""}),A.website&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.website.message})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone Number *"}),jsxRuntime.jsx(Input,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:o,...S("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:A.phone||z(E("phone"))?"input-error-indicator":""}),A.phone&&jsxRuntime.jsx("p",{className:"text-red-500 text-sm",children:A.phone.message})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{type:"submit",disabled:I||o,className:o?"hidden":"",children:I?"Saving...":"Save"})})]})]})]})};function BillingCard({appID:t,reseller:e,isLoading:n,withoutReports:o}){const{Statement:l,CreditLimit:d}=e,f=[{label:"0 - 30 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over0)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:Calendar},{label:"31 - 45 Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over30)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarDays},{label:"45+ Days",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Over45)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CalendarRange},{label:"Total",value:jsxRuntime.jsx(FormattedNumber,{value:(l==null?void 0:l.Total)||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:DollarSign},{label:"Credit Limit",value:jsxRuntime.jsx(FormattedNumber,{value:d||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:CreditCard}],g=()=>{const _=`https://dashboard.randmar.io/${t}/PayInvoice`;window.open(_,"_blank","noopener,noreferrer")};if(n)return jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(Skeleton,{className:"h-6 w-36"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:[1,2,3].map(_=>jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]},_))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:[1,2].map(_=>jsxRuntime.jsx("div",{className:_===2?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 ms-auto"})]})},_))})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-28 mt-6"})})]})]});const b=!o;return jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{className:"border-b p-6 md:p-5",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Billing Overview"})}),jsxRuntime.jsxs(CardContent,{className:"p-6 md:p-5",children:[jsxRuntime.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[jsxRuntime.jsx("div",{className:"space-y-6 sm:pe-4",children:f.slice(0,3).map((_,S)=>jsxRuntime.jsx(BillingItem,{icon:_.icon,label:_.label,value:_.value},S))}),jsxRuntime.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:f.slice(3).map((_,S)=>jsxRuntime.jsx("div",{className:S===1?"pt-6 mt-6 border-t border-border":"",children:jsxRuntime.jsx(BillingItem,{icon:_.icon,label:_.label,value:_.value})},S))})]}),b&&jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(Button,{className:"mt-6",onClick:g,children:"Pay Invoices"})})]})]})}function BillingItem({icon:t,label:e,value:n}){return jsxRuntime.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(t,{className:"size-4 text-muted-foreground"}),jsxRuntime.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:e})]}),jsxRuntime.jsx("span",{className:"text-base font-semibold ms-auto",children:n})]})}function ChangePricingTierModal({open:t,setOpen:e,tier:n,onTierChange:o,isLoading:l}){const d=()=>{e(!1)};return jsxRuntime.jsx(Dialog,{open:t,onOpenChange:e,children:jsxRuntime.jsxs(DialogContent,{className:"sm:max-w-[425px]",children:[jsxRuntime.jsx(DialogHeader,{children:jsxRuntime.jsx(DialogTitle,{children:"Change Pricing Tier"})}),jsxRuntime.jsxs("div",{className:"grid gap-1.5 py-2",children:[jsxRuntime.jsxs("p",{className:"text-lg text-muted-foreground",children:["Requested Pricing Tier: ",jsxRuntime.jsx("span",{className:"font-bold",children:n})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If your account qualifies, your pricing will update immediately."}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"If not, we'll review your request and notify you of the decision."})]}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:d,disabled:l,children:"Cancel"}),jsxRuntime.jsx(Button,{onClick:o,disabled:l,children:l?"Loading...":`Apply for ${n}`})]})]})})}const getPricingText=t=>t===1?"The Best":t===2?"Fixed 12.5% GP on all items":t===3?"Advantageous":t===4?"Buying Group":t===5?"Cost":t,getShippingText=t=>t==="A"?"Free or Custom":t==="B"?"Fixed $10 anywhere":t==="C"?`Free shipping on $150+ orders to your location,
1073
1073
  $15 for drop shipped orders under $1,500,
1074
1074
  $10 with opportunities under $1,000`:t==="D"?"$15 under $1,500":t==="E"?"Full shipping charges":t,getTermsText=t=>t==="STRIPE"?"Credit card payment":t==="NET30"?"Net 30 days":t,AccountTier=({isSuperAdmin:t,readonly:e,reseller:n,appID:o,isLoading:l})=>{const{toast:d}=useToast(),[f,g]=React.useState(!1),[b,_]=React.useState(""),[S,{isLoading:R}]=usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),C=Oe=>Oe&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[Oe]||"",E=Oe=>Oe&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[Oe]||"",A=Oe=>Oe&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[Oe]||"",[I,M]=React.useState(C((n==null?void 0:n.Priority)??"")),[j,q]=React.useState(E((n==null?void 0:n.ShippingProfile)??"")),[z,Q]=React.useState(A(n==null?void 0:n.PriceProfile)),F=Oe=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[Oe]||Oe,V=Oe=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[Oe]||Oe,te=Oe=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[Oe]||Oe;React.useEffect(()=>{M(C((n==null?void 0:n.Priority)??"")),q(E((n==null?void 0:n.ShippingProfile)??"")),Q(A(n==null?void 0:n.PriceProfile))},[n]);const ne=async(Oe,Fe,ze,$e)=>{try{(await S({applicationId:o,fieldName:Oe,newValue:Fe})).error?d({title:"Error",description:$e,variant:"destructive"}):d({title:"Success",description:ze,variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},se=async Oe=>{M(Oe);const Fe=F(Oe);ne("Priority",Fe,`Priority updated to ${Fe}`,"Failed to update priority")},ge=async Oe=>{q(Oe);const Fe=V(Oe);ne("ShippingProfile",Fe,`Shipping profile updated to ${Fe}`,"Failed to update shipping profile")},oe=async Oe=>{Q(Oe);const Fe=te(Oe);ne("PriceProfile",Fe,`Pricing profile updated to ${Fe}`,"Failed to update pricing profile")},Ae=async()=>{try{const Oe=await S({applicationId:o,fieldName:"Tier",newValue:b});Oe.error?d({title:"Error",description:"Failed to update reseller",variant:"destructive"}):Oe.data?d({title:"Success",description:`Pricing Tier changed to ${b}`,variant:"success"}):d({title:"Considered",description:"Request being considered",variant:"success"})}catch{d({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}finally{g(!1),_("")}},je=[{name:"Terms",enabled:n.Priority==="Starter"},{name:"E-Commerce",enabled:n.Priority==="Commercial"},{name:"Commercial",enabled:n.Priority==="E-Commerce"},{name:"Exclusive",enabled:t}],Ne=Oe=>{_(Oe),g(!0)};return l?jsxRuntime.jsxs(Card,{className:"md:col-span-2 xl:col-span-1 md:max-w-xl xl:max-w-[unset]",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-28"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-16 rounded-full"})]})}),jsxRuntime.jsxs(CardContent,{children:[jsxRuntime.jsxs("div",{className:"mb-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-56"})]}),jsxRuntime.jsx("div",{className:"grid gap-3",children:[1,2,3].map(Oe=>jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]})]},Oe))}),jsxRuntime.jsxs("div",{className:"flex gap-2 mt-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full"})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"md:col-span-2 xl:col-span-1 md:max-w-xl xl:max-w-[unset]",children:[jsxRuntime.jsxs(CardHeader,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Account Tier"}),jsxRuntime.jsx(Badge,{variant:"secondary",className:"bg-green-100 text-green-700 hover:bg-green-200 text-xs",children:"Active"})]}),jsxRuntime.jsxs(CardContent,{className:"pt-2 px-4 pb-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-3 bg-primary/5 p-4 rounded-lg",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h3",{className:"text-lg font-bold text-primary",children:[(n==null?void 0:n.Priority)||""," Tier"]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Optimized for online retail"})]}),jsxRuntime.jsx(CircleCheck,{className:"h-6 w-6 text-green-600"})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Package2,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Pricing"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground truncate",children:getPricingText(n.PriceProfile||0)})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Truck,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Shipping"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getShippingText(n.ShippingProfile||"").split(".")[0]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:jsxRuntime.jsx(Calendar,{className:"h-4 w-4 text-primary"})}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-sm",children:"Payment terms"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:getTermsText((n==null?void 0:n.Terms)||"")})]})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[!e&&jsxRuntime.jsx(Button,{variant:"outline",className:"flex-1",asChild:!0,children:jsxRuntime.jsxs("a",{href:"https://www.randmar.io/docs/overview/pricingTiers",target:"_blank",rel:"noreferrer",children:[jsxRuntime.jsx(ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),jsxRuntime.jsxs(Popover,{children:[jsxRuntime.jsx(PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(Button,{disabled:e,className:e?"hidden":"flex-1",children:["Upgrade Tier ",jsxRuntime.jsx(ChevronRight,{className:"h-3 w-3 ml-1"})]})}),jsxRuntime.jsx(PopoverContent,{className:"w-56 p-2",children:jsxRuntime.jsxs("div",{className:"grid gap-1",children:[jsxRuntime.jsx("h4",{className:"font-medium text-xs mb-1",children:"Select a tier"}),je.map(Oe=>jsxRuntime.jsx(Button,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!Oe.enabled,onClick:()=>Ne(Oe.name),children:Oe.name},Oe.name))]})})]})]})]})]}),jsxRuntime.jsx(ChangePricingTierModal,{isLoading:R,open:f,setOpen:g,tier:b,onTierChange:Ae}),t&&!e&&jsxRuntime.jsxs(Card,{className:"mt-4",children:[jsxRuntime.jsx(CardHeader,{className:"pb-2 pt-3 px-4",children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Admin Configuration"})}),jsxRuntime.jsx(CardContent,{className:"pt-2 px-4 pb-4",children:jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Priority"}),jsxRuntime.jsx(RadioGroup$1,{value:I,onValueChange:se,className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 gap-1",children:[{value:"starter",label:"Starter"},{value:"ecommerce",label:"E-Commerce"},{value:"commercial",label:"Commercial"},{value:"cws",label:"CWS (Basics)"},{value:"novexco",label:"Novexco"},{value:"jeancoutu",label:"Jean Coutu"},{value:"exclusive",label:"Exclusive"}].map(Oe=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:Oe.value,id:`priority-${Oe.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`priority-${Oe.value}`,className:"cursor-pointer text-xs",children:Oe.label})]},Oe.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:j,onValueChange:ge,className:"grid grid-cols-1 @md:grid-cols-2 gap-1",children:[{value:"free",label:"Free (A)"},{value:"fixed",label:"Fixed $10 Shipping (B)"},{value:"dropshipped",label:"$15 for drop shipped (C)"},{value:"under1500",label:"15$ under 1,500 (D)"},{value:"fullcharges",label:"Full shipping charges (E)"}].map(Oe=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:Oe.value,id:`shipping-${Oe.value}`,className:"h-6 w-6 scale-50"}),jsxRuntime.jsx(Label$2,{htmlFor:`shipping-${Oe.value}`,className:"cursor-pointer text-xs",children:Oe.label})]},Oe.value))})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[jsxRuntime.jsx(Label$2,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),jsxRuntime.jsx(RadioGroup$1,{value:z,onValueChange:oe,className:"grid grid-cols-2 @sm:grid-cols-3 gap-1",children:[{value:"exclusive",label:"Exclusive (1)"},{value:"ecommerce",label:"E-Commerce (2)"},{value:"commercial",label:"Commercial (3)"},{value:"buyinggroup",label:"Buying Group (4)"},{value:"cost",label:"Cost (5)"}].map(Oe=>jsxRuntime.jsxs("div",{className:"flex items-center space-x-1",children:[jsxRuntime.jsx(RadioGroupItem,{value:Oe.value,id:`pricing-${Oe.value}`,className:"h-6 w-6 scale-50 antialiased"}),jsxRuntime.jsx(Label$2,{htmlFor:`pricing-${Oe.value}`,className:"cursor-pointer text-xs",children:Oe.label})]},Oe.value))})]})]})})]})]})};function OrderCategories({openOrders:t=[],isLoading:e=!1}){const n=(t==null?void 0:t.filter(I=>I.DocumentType==="Order"))||[],o=(t==null?void 0:t.filter(I=>I.DocumentType==="Shipment"))||[],l=n.filter(I=>I.WarehouseCode!=="3PLE"),d=l.reduce((I,M)=>I+(M.Quantity??0),0),f=l.reduce((I,M)=>I+(M.ExtendedPrice??0),0),g=n.filter(I=>I.WarehouseCode==="3PLE"),b=g.reduce((I,M)=>I+(M.Quantity??0),0),_=g.reduce((I,M)=>I+(M.ExtendedPrice??0),0),S=o.reduce((I,M)=>I+(M.Quantity??0),0),R=o.reduce((I,M)=>I+(M.ExtendedPrice??0),0),C=d+b+S,E=f+_+R,A=[{name:"All",icon:Package,color:"bg-blue-500",orders:C,amount:E},{name:"Processing",icon:RefreshCcw,color:"bg-yellow-500",orders:d,amount:f},{name:"Shipped",icon:Truck,color:"bg-green-500",orders:S,amount:R},{name:"Delayed",icon:CircleAlert,color:"bg-red-500",orders:b,amount:_}];return e?jsxRuntime.jsxs(Card,{className:"w-full @md:col-span-2 @xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-40"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(I=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:"bg-gray-200 h-[3px]"}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-8 w-8 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-12"})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-20 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20"})]})]})]})]})},I))})})]}):jsxRuntime.jsxs(Card,{className:"w-full @md:col-span-2 @xl:col-span-1",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Order Categories"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:A.map(I=>jsxRuntime.jsx(Card,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:jsxRuntime.jsxs(CardContent,{className:"p-0",children:[jsxRuntime.jsx("div",{className:`${I.color} bg-opacity-60 h-[3px]`}),jsxRuntime.jsxs("div",{className:"p-6 border border-t-0",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-base",children:I.name}),jsxRuntime.jsx("div",{className:`${I.color} bg-opacity-90 p-2 rounded-full`,children:jsxRuntime.jsx(I.icon,{className:"size-4 shrink-0 text-white"})})]}),jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),jsxRuntime.jsx("p",{className:"text-xl font-bold",children:I.orders})]}),jsxRuntime.jsxs("div",{className:"text-end",children:[jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),jsxRuntime.jsx("p",{className:"text-base font-semibold",children:jsxRuntime.jsx(FormattedNumber,{value:I.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},I.name))})})]})}function ReportsSection({isLoading:t,userEmail:e,appID:n}){const{toast:o}=useToast(),[l,{isLoading:d}]=usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[f,{isLoading:g}]=usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[b,{isLoading:_}]=usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[S,{isLoading:R}]=usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[C,{isLoading:E}]=usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[A,{isLoading:I}]=usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[M,j]=React.useState(null),[q,z]=React.useState(e),[Q,F]=React.useState(!1),V=[{name:"Products",reports:[{id:"Products",title:"Universal Product List",description:"A comprehensive overview of your product list with detailed specifications and pricing information.",icon:Package}]},{name:"Operation Details",reports:[{id:"OpenOrders",title:"Order Details",description:"A detailed report of all your orders and shipments, including status, tracking information, and delivery estimates.",icon:ShoppingCart},{id:"Invoices",title:"Invoices and Credits Report",description:"Detailed overview of your invoices and credits within a specific date range. It also contains reports about additional charges, serial numbers, and other relevant information.",icon:ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:Banknote}]},{name:"Tracking Files",reports:[{id:"AmazonTrackingFile",title:"Amazon Tracking File",description:"Track products sold on Amazon marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:ChartNoAxesColumnIncreasing}]}],te=async ge=>{j(ge),F(!0)},ne=async()=>{if(!(!M||!n))try{switch(M.id){case"Products":await S({routeResellerId:n,emailAddress:q}).unwrap();break;case"AmazonTrackingFile":await f({routeResellerId:n,emailAddress:q}).unwrap();break;case"WalmartTrackingFile":await l({routeResellerId:n,emailAddress:q}).unwrap();break;case"OpenOrders":await b({routeResellerId:n,emailAddress:q}).unwrap();break;case"Invoices":await C({routeResellerId:n,emailAddress:q}).unwrap();break;case"Statement":await A({routeResellerId:n,emailAddress:q}).unwrap();break;default:throw new Error("invalid report id")}o({title:"Report requested",description:`The ${M.title} will be sent to ${q} shortly.`,variant:"success"}),F(!1)}catch(ge){console.error("Error requesting report:",ge),o({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},se=_||R||g||d||I||E;return jsxRuntime.jsxs(Card,{children:[jsxRuntime.jsxs(CardHeader,{children:[jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Reports"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Product List to your Order Details."})]}),jsxRuntime.jsx(CardContent,{className:"space-y-6",children:t?jsxRuntime.jsx(jsxRuntime.Fragment,{children:[1,2,3].map(ge=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-48"}),[1,2].map(oe=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-9 rounded-full"}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full"})]}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})]},oe))]},ge))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:V.map(ge=>jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:ge.name}),ge.reports.map(oe=>jsxRuntime.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg hover:bg-gray-100 transition-colors",children:[jsxRuntime.jsx("div",{className:"bg-primary/10 p-2 rounded-full",children:jsxRuntime.jsx(oe.icon,{className:"h-5 w-5 text-primary"})}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("h4",{className:"font-semibold text-sm",children:oe.title}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:oe.description})]}),jsxRuntime.jsxs(Button,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>te(oe),children:[jsxRuntime.jsx(Download,{className:"h-4 w-4"}),"Request"]})]},oe.id))]},ge.name))})}),jsxRuntime.jsx(Dialog,{open:Q,onOpenChange:F,children:jsxRuntime.jsxs(DialogContent,{children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsxs(DialogTitle,{children:["Request ",M==null?void 0:M.title]}),jsxRuntime.jsx(DialogDescription,{children:"Enter the email address where you would like to receive the report."})]}),jsxRuntime.jsxs("div",{className:"py-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",value:q,onChange:ge=>z(ge.target.value),placeholder:"your@email.com",className:"mt-2"})]}),jsxRuntime.jsx(DialogDescription,{children:"The report will take around 5 minutes to generate."}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button,{variant:"outline",onClick:()=>F(!1),children:"Cancel"}),jsxRuntime.jsx(Button,{onClick:ne,disabled:!q||se,children:se?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}const badgeVariants=cva("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground border border-input hover:bg-accent hover:text-accent-foreground",success:"bg-green-600 text-white hover:bg-green-700",warning:"bg-yellow-500 text-white hover:bg-yellow-600",info:"bg-blue-500 text-white hover:bg-blue-600",ghost:"bg-background hover:bg-accent hover:text-accent-foreground",randmarRed:"bg-randmar-red text-white hover:bg-randmar-red/80",randmarBlue:"bg-randmar-blue text-white hover:bg-randmar-blue/80",randmarPurple:"bg-randmar-purple text-white hover:bg-randmar-purple/80",randmarGreen:"bg-randmar-green text-black hover:bg-randmar-green/80",randmarBlack:"bg-randmar-black text-white hover:bg-randmar-black/80",randmarYellow:"bg-randmar-yellow text-black hover:bg-randmar-yellow/80"},size:{default:"h-6",sm:"h-5 text-[10px]",lg:"h-7 px-3"}},defaultVariants:{variant:"default",size:"default"}}),Badge=React__namespace.forwardRef(({className:t,variant:e,size:n,icon:o,children:l,...d},f)=>jsxRuntime.jsxs("div",{ref:f,className:cn(badgeVariants({variant:e,size:n}),t),...d,children:[o&&jsxRuntime.jsx("span",{className:"mr-1",children:o}),l]}));Badge.displayName="Badge";function QualificationBadge({qualification:t}){return!t.QualificationId||t.QualificationId==="Suspended"?null:t.QualificationId==="Do Not Sell"?jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"destructive",children:[jsxRuntime.jsx(X$1,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})}):jsxRuntime.jsx(TooltipProvider,{children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs(Badge,{variant:"info",className:t.DefaultOpportunityNumber?"pr-1":"",children:[jsxRuntime.jsx(BadgeCheck,{className:"h-3 w-3 mr-1"}),t.QualificationId,t.DefaultOpportunityNumber&&jsxRuntime.jsx(Badge,{variant:"secondary",size:"sm",className:"ml-1",children:t.DefaultOpportunityNumber})]})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsx("p",{children:"Qualification"})})]})})}function useIntersectionObserver({elementRef:t,threshold:e=0,rootMargin:n="0px",freezeOnceVisible:o=!1}){const[l,d]=React.useState(!1);return React.useEffect(()=>{const f=t.current;if(!f){d(!1);return}const g=new IntersectionObserver(([b])=>{const _=b.isIntersecting;o&&_?(d(!0),g.unobserve(f)):d(_)},{threshold:e,rootMargin:n});return g.observe(f),()=>{g.unobserve(f)}},[t,e,n,o]),l}const PartnerLogo=({id:t,name:e,width:n=64,height:o=64,align:l=""})=>{const d=React.useRef(null),[f,g]=React.useState(!1),[b,_]=React.useState(null),S=useIntersectionObserver({elementRef:d,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{data:R,isFetching:C}=useGetV4PartnerByApplicationIdAccountLogoExistsQuery({applicationId:t??""},{skip:!t||!S});React.useEffect(()=>{_(null),!(!t||C||!R||R==="false")&&(g(!0),fetch(`https://api.randmar.io/V4/Partner/${t}/Account/Logo?width=${n}&height=${o}&align=${l}`).then(M=>{M.ok||console.error("error fetching logo"),M.blob().then(j=>{const q=window.URL.createObjectURL(j);_(q)})}).catch(M=>{console.error("error loading logo",M)}).finally(()=>{g(!1)}))},[t,R,C]);const E="No Logo",A=e||(t?`Partner ID: ${t}`:"Logo not available (no ID)"),I=()=>!S||C||f?jsxRuntime.jsx(Skeleton,{className:"h-full w-full rounded-sm"}):b?jsxRuntime.jsx("img",{src:b,alt:A,className:"h-full w-full object-contain rounded-sm"}):jsxRuntime.jsx("div",{className:"flex h-full w-full items-center justify-center border border-dashed border-border rounded-sm bg-muted/20 p-1",title:A,children:jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground font-mono text-center leading-none",children:E})});return jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("div",{className:"flex h-full w-full cursor-default",ref:d,children:I()})}),jsxRuntime.jsx(TooltipContent,{side:"top",align:"center",children:A})]})})};function ManufacturerCard({manufacturer:t,link:e,linkNewTab:n=!0,actions:o,mainAction:l,loading:d=!1}){var C,E,A;if(d||!t)return jsxRuntime.jsxs(Card,{className:"flex flex-col h-full",children:[jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-12 rounded-md"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(Skeleton,{className:"h-3 w-24 mb-2"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-40 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32 mb-1"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-48"})]})]}),jsxRuntime.jsx(Skeleton,{className:"h-16 w-24"})]}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex flex-col space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-16 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-20 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-14 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-32"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-40"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-4"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-36"})]})]})]})}),jsxRuntime.jsxs(CardFooter,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-40"})]})]});const f=t.ManufacturerId||"N/A",g=[t.City,t.Province,t.Country].filter(Boolean),b=g.length>0?g.join(", "):"",_=((C=t.Tags)==null?void 0:C.split(",").map(I=>I.trim()).filter(Boolean))||[],R=(I=>!I||I.length===0?[]:[...I].sort((M,j)=>(M.Day||0)-(j.Day||0)).map(M=>({date:M.Day||0,amount:M.ExtendedPrice||0})))(t.SalesStatistics);return jsxRuntime.jsxs(Card,{className:"manufacturer-theme flex flex-col h-full",children:[jsxRuntime.jsx(reactRouterDom.Link,{to:e??"#",target:e&&n?"_blank":"_self",children:jsxRuntime.jsxs(CardHeader,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"h-12 w-12 overflow-hidden rounded-md",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,width:48,height:48})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-primary",children:"Manufacturer"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"|"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:f})]}),jsxRuntime.jsx("h3",{className:"font-semibold",children:t.PublicName||"N/A"}),t.Name&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t.Name}),b&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:b})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col items-end gap-2",children:R.length>0&&jsxRuntime.jsx("div",{className:"h-16 w-24",children:jsxRuntime.jsx(AreaChart,{data:R,height:60,size:"mini"})})})]})}),jsxRuntime.jsx(CardContent,{className:"pb-2 flex-grow",children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(!!((E=t.Qualification)!=null&&E.QualificationId)&&((A=t.Qualification)==null?void 0:A.QualificationId)!=="Suspended"||!!t.OpenToWork||!!t.OnHold&&t.OnHold!==0||_.length>0)&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(QualificationBadge,{qualification:t.Qualification??{}}),!!t.OpenToWork&&jsxRuntime.jsxs(Badge,{variant:"success",children:[jsxRuntime.jsx(HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!t.OnHold&&t.OnHold!==0&&jsxRuntime.jsx(Badge,{variant:"warning",children:"On Hold"}),_.map((I,M)=>jsxRuntime.jsx(Badge,{variant:"outline",children:I},M))]}),jsxRuntime.jsxs("div",{className:"space-y-1 pt-2",children:[t.Phone&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`tel:${t.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Phone,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:t.Phone})]}),t.PublicEmail&&jsxRuntime.jsxs(reactRouterDom.Link,{to:`mailto:${t.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Mail,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:t.PublicEmail})]}),t.Website&&jsxRuntime.jsxs(reactRouterDom.Link,{to:t.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(Globe,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:t.Website})]}),t.CurrencyCode&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[jsxRuntime.jsx(DollarSign,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:t.CurrencyCode})]})]})]}),t.SalesData&&jsxRuntime.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[jsxRuntime.jsx("strong",{className:"",children:"YTD"}),jsxRuntime.jsx("p",{children:t.SalesData.SalesYearToDay?formatMoney(t.SalesData.SalesYearToDay):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"3 mo."}),jsxRuntime.jsx("p",{children:t.SalesData.SalesLast3Months?formatMoney(t.SalesData.SalesLast3Months):"—"}),jsxRuntime.jsx("strong",{className:"mt-2",children:"30 days"}),jsxRuntime.jsx("p",{children:t.SalesData.SalesLast30Days?formatMoney(t.SalesData.SalesLast30Days):"—"})]})]})}),(o||l)&&jsxRuntime.jsxs(CardFooter,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:o&&o}),l&&jsxRuntime.jsx("div",{children:l})]})]})}function ResellerOverview({appID:t,reseller:e,readonly:n,userEmail:o,isSuperAdmin:l,withoutReports:d=!1}){const{data:f,isLoading:g,isError:b}=useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:t??"",withSpecification:!0},{skip:!!e}),[_,S]=React.useState({publicInfo:{hasUnsavedChanges:!1}}),R=React.useCallback(()=>n?!1:_.publicInfo.hasUnsavedChanges,[n,_]),C=React.useCallback((q,z)=>{S(Q=>{var F;return((F=Q[q])==null?void 0:F.hasUnsavedChanges)!==z.hasUnsavedChanges?{...Q,[q]:z}:Q})},[]),{NavigationGuardDialog:E}=useRouterNavigationGuard(R),A=e??f,I=!n||!!(A!=null&&A.Statement)&&(A.Statement.Total??0)>0,M=(A==null?void 0:A.QualifiedManufacturers)??[],j=(A==null?void 0:A.Qualifications)??[];return jsxRuntime.jsxs("div",{className:"@container",children:[b?jsxRuntime.jsx(Card,{className:"p-6",children:jsxRuntime.jsxs(Alert,{variant:"destructive",children:[jsxRuntime.jsx(CircleAlert,{className:"h-4 w-4"}),jsxRuntime.jsx(AlertTitle,{children:"Error"}),jsxRuntime.jsx(AlertDescription,{children:"There was an error loading your reseller information. Please try again later."})]})}):jsxRuntime.jsxs("div",{className:"space-y-6 mb-6",children:[jsxRuntime.jsx(SalesSummary,{fiscalYearMonthStart:(A==null?void 0:A.FiscalYearMonthStart)||1,salesData:A==null?void 0:A.SalesData,isLoading:g}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 @2xl:grid-cols-2 gap-6",children:[jsxRuntime.jsx(SalesChart,{salesData:(A==null?void 0:A.SalesStatistics)??[],isLoading:g}),jsxRuntime.jsx(OrderCategories,{openOrders:(A==null?void 0:A.ActiveOrderDetails)??[],isLoading:g}),I&&jsxRuntime.jsx(BillingCard,{appID:t,reseller:A||{},withoutReports:d,isLoading:g}),jsxRuntime.jsx(PublicInfo,{reseller:A||{},appID:t??"",isLoading:g,readonly:n,onUnsavedChanges:q=>C("publicInfo",{hasUnsavedChanges:q})}),jsxRuntime.jsx(AccountTier,{isSuperAdmin:l,readonly:n,reseller:A||{},appID:t??"",isLoading:g})]}),g||M.length>0?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{children:"Manufacturers you are qualified for"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx("div",{className:"grid @2xl:grid-cols-2 gap-4",children:g?Array.from({length:2}).map((q,z)=>jsxRuntime.jsx(ManufacturerCard,{loading:!0},z)):M.map(q=>jsxRuntime.jsx(ManufacturerCard,{manufacturer:q,link:`https://dashboard.randmar.io/${t}/Partner/${q.ManufacturerId}`},q.ManufacturerId))})})]}):jsxRuntime.jsx(ResellerQualificationsCard,{qualifications:j}),jsxRuntime.jsx(OpportunitiesTable,{applicationId:t,opportunities:A==null?void 0:A.Opportunities,loading:g}),!d&&jsxRuntime.jsx(ReportsSection,{appID:t,userEmail:o,isLoading:g})]}),jsxRuntime.jsx(E,{})]})}const alertVariants=cva("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",success:"border-green-500/50 bg-green-50 text-green-700 dark:border-green-500 dark:bg-green-950 dark:text-green-400 [&>svg]:text-green-500",warning:"border-yellow-500/50 bg-yellow-50 text-yellow-700 dark:border-yellow-500 dark:bg-yellow-950 dark:text-yellow-400 [&>svg]:text-yellow-500",info:"border-blue-500/50 bg-blue-50 text-blue-700 dark:border-blue-500 dark:bg-blue-950 dark:text-blue-400 [&>svg]:text-blue-500"}},defaultVariants:{variant:"default"}}),Alert=React__namespace.forwardRef(({className:t,variant:e,...n},o)=>jsxRuntime.jsx("div",{ref:o,role:"alert",className:cn(alertVariants({variant:e}),t),...n}));Alert.displayName="Alert";const AlertTitle=React__namespace.forwardRef(({className:t,...e},n)=>jsxRuntime.jsx("h5",{ref:n,className:cn("mb-1 font-medium leading-none tracking-tight",t),...e}));AlertTitle.displayName="AlertTitle";const AlertDescription=React__namespace.forwardRef(({className:t,...e},n)=>jsxRuntime.jsx("div",{ref:n,className:cn("text-sm [&_p]:leading-relaxed",t),...e}));AlertDescription.displayName="AlertDescription";/**
1075
1075
  * table-core
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "randmarcomps",
3
3
  "private": false,
4
- "version": "1.289.0",
4
+ "version": "1.290.0",
5
5
  "description": "The UI library enabling speed and consistency in Randmar frontends.",
6
6
  "type": "module",
7
7
  "files": [