@e-llm-studio/instant-learning 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/features/LearningManagement/LearningManagement.js +1 -1
- package/dist/cjs/features/LearningManagement/RuleContent/RuleAccordionHeader.js +1 -1
- package/dist/cjs/features/LearningManagement/RuleContent/VariantCard.js +1 -1
- package/dist/cjs/features/LearningManagement/apis/scopeApis.js +1 -1
- package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/cjs/features/LearningManagement/queries/useApprovalQueries.js +1 -1
- package/dist/features/LearningManagement/LearningManagement.js +1 -1
- package/dist/features/LearningManagement/RuleContent/RuleAccordionHeader.js +1 -1
- package/dist/features/LearningManagement/RuleContent/VariantCard.js +1 -1
- package/dist/features/LearningManagement/apis/scopeApis.js +1 -1
- package/dist/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/features/LearningManagement/queries/useApprovalQueries.js +1 -1
- package/dist/types/src/features/LearningManagement/RuleContent/RuleAccordionHeader.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/RuleContent/VariantCard.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts +11 -1
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/InstantLearningModal.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/queries/useApprovalQueries.d.ts +4 -0
- package/dist/types/src/features/LearningManagement/queries/useApprovalQueries.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as e,__spreadArray as n,__awaiter as t,__generator as i}from"tslib";import{jsxs as r,jsx as a,Fragment as o}from"react/jsx-runtime";import l,{useState as s,useRef as u,useEffect as d,useCallback as c,useMemo as v}from"react";import{AlertTriangle as _,Loader as p,Check as f}from"lucide-react";import{Toast as g}from"primereact/toast";import{v4 as m}from"uuid";import{saveInstantLearningQuestion as w,publishFeedback as y,updateVariant as h,fetchRulesByQuestionId as b,submitChatFeedback as T}from"../apis/scopeApis.js";import A from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as M}from"../store/useLearningTemplateStore.js";import I from"../styles/InstantLearningModal.module.css.js";import S from"../../IL-OTJ/ILOTJ.js";import"../../IL-OTJ/_components/atoms/Textarea/Textarea.js";import"../../IL-OTJ/_components/InputDataReasoningCard.js";import"../../IL-OTJ/_components/TooltipComponent.js";import{TemplateList as k}from"../../IL-OTJ/_components/templates/TemplatesMap/templatesMap.js";import{extractAndParseWithProperty as N,parseValidationData as C,extractAndParseResponse as x,extractVariantIds as E}from"../../IL-OTJ/helpers/utils.js";import{useCitations as O}from"../../IL-OTJ/store/CitationsContext.js";import"@mui/material";import"@mui/material/Tooltip";import"react-markdown";import"rehype-raw";import"axios";import"@e-llm-studio/streaming-response";import"@e-llm-studio/watch-me-work";import"../../IL-OTJ/_components/ChatComponents/ChatHeader.js";import"remark-gfm";import"../../IL-OTJ/_components/MarkdownComponents/MarkdownElements.js";import"../../IL-OTJ/_components/CitationLink.js";import"@e-llm-studio/citation";import"@viswa-test/test-citation";import"../LearningManagement.js";import L from"../store/useAuthStore.js";import{useConfigStore as R}from"../store/useConfigStore.js";import{IL_CONFIG_CONSTANTS as D}from"../config.js";var j=function(){return a("img",{src:A,alt:"Thinking...",width:"20",height:"20"})},V="INITIAL",P="SUCCESS",G="FAILURE",F="IN_PROGRESS",q=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},U=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},J=function(e){return e.toLowerCase().replace(/ /g,"_").replace(/tier(\d+)/i,"tier_$1")},H=function(A){var H,B,W,Y,K,Q,z=A.isOpen,Z=A.onClose,$=A.initialScope,X=void 0===$?"global":$,ee=A.ruleSet,ne=A.editingRule,te=A.editingTier,ie=A.editingVariants,re=A.focusedVariantIndex,ae=A.setFocusedVariantIndex,oe=A.triggerAddVariant,le=A.triggerFixGaps,se=A.copiedRule,ue=A.copiedSourceTier,de=A.copiedTargetTier,ce=A.initialDraftMessage,ve=A.initialChatMessage,_e=A.applicationIntegrationId;A.modeId;var pe=s({station:X,tiers:["Tier 1"]}),fe=pe[0],ge=pe[1],me=s(V),we=me[0],ye=me[1],he=s(!1),be=he[0],Te=he[1],Ae=s("Thank you teacher for teaching me, your rule has been saved successfully."),Me=Ae[0];Ae[1];var Ie=s(""),Se=Ie[0],ke=Ie[1],Ne=s(!1),Ce=Ne[0],xe=Ne[1],Ee=u(null),Oe=s(!1),Le=Oe[0],Re=Oe[1],De=u(!1),je=M().tiers,Ve=l.useRef(new Set),Pe=s(null);Pe[0];var Ge=Pe[1],Fe=s(null);Fe[0];var qe=Fe[1],Ue=s(null);Ue[0];var Je=Ue[1],He=u({}),Be=u(new Map),We=u(""),Ye=u(!1),Ke=s(0),Qe=Ke[0],ze=Ke[1],Ze=s(!1),$e=Ze[0],Xe=Ze[1],en=u(null),nn=u(0),tn=s(null),rn=tn[0],an=tn[1],on=s([]),ln=on[0],sn=on[1],un=s(null),dn=un[0],cn=un[1],vn=s(null),_n=vn[0],pn=vn[1],fn=s(!1),gn=fn[0],mn=fn[1],wn=u({}),yn=u([]),hn=u(!1),bn=s(!1),Tn=bn[0],An=bn[1],Mn=u(!1),In=u(new Set),Sn=s(null),kn=Sn[0],Nn=Sn[1],Cn=s(null),xn=Cn[0],En=Cn[1],On=s(null),Ln=On[0],Rn=On[1],Dn=u(null),jn=u(null),Vn=u(null),Pn=u({}),Gn=u([]),Fn=u([]),qn=u({}),Un=R(),Jn=Un.configuration,Hn=Un.ilLabels,Bn=M.getState().backwardCompatibility;d(function(){kn||En(null)},[kn]),d(function(){var e;if(z&&ne){Dn.current=ne.ruleId;var n=null===(e=null==ie?void 0:ie[re||0])||void 0===e?void 0:e.variantId;Rn(n||null)}},[z,ne,ie,re]),d(function(){z&&ge(function(n){return e(e({},n),{station:X})})},[z,X]),d(function(){console.log("triggered",Ln),console.log(mt,"structuredAIResponse"),wt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Ln&&n.new_variant_id!==Ln})}):n}),Mt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Ln&&n.new_variant_id!==Ln})}):n})},[Ln]),d(function(){var n;if(!z)return Ir(),void(hn.current=!1);if(!hn.current){var t=ie,i=t&&t.length>0,r=null!=ne;if(i||r){if((null==ne?void 0:ne.ruleTitle)&&it(ne.ruleTitle),te&&(ge(function(n){return e(e({},n),{tiers:[te]})}),jn.current=te.toLowerCase().replace(/ /g,"_")),i){var a=te?J(te):"tier_1",o=new Map,l=new Map,s=new Map,u=new Map,d=new Map,c=new Map,v=[];t.forEach(function(e,n){u.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];c.set(n,i),v.push(e.variantId||e.variant_id||"")}),o.set(a,u),l.set(a,d),s.set(a,c);var _=null===(n=null==t?void 0:t[re||0])||void 0===n?void 0:n.variantId,p=t.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:(null==ne?void 0:ne.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==ne?void 0:ne.ruleId)||"",tier_id:a.replace("tier_",""),is_readOnly:e.variantId!==_,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});wt(p),wt(p),Mt(p),bt(function(e){var n=new Map(e);return n.set(a,JSON.parse(JSON.stringify(p))),n});var f=new Map;t.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,w=null!==(s=null!==(o=null==g?void 0:g.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==g?void 0:g.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;f.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:w>0,global_min_separation_seconds:Math.floor(w/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==g?void 0:g.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==g?void 0:g.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==g?void 0:g.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==g?void 0:g.respect_break_code)&&void 0!==p&&p},is_default_enabled:U(e.variantType||e.variant_type)})}),Qn(new Map([[a,f]])),ut(o),vt(l),ft(s)}else if(r&&ne){var g=ne.ruleDesc;if(g&&ut(new Map([["tier_1",new Map([[0,g]])]])),ne.whenToApply){var m=ne.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wta-".concat(n),text:e,reasoning:""}});vt(new Map([["tier_1",new Map([[0,m]])]]))}if(ne.whenNotToApply){var w=ne.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wnta-".concat(n),text:e,reasoning:""}});ft(new Map([["tier_1",new Map([[0,w]])]]))}}}else if(se&&ue&&de){it(se.ruleTitle||""),ge(function(n){return e(e({},n),{tiers:[de]})}),jn.current=J(de);var y=J(ue),h=se.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),T=new Map,A=new Map;h.forEach(function(e,n){b.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e,t){return{id:"copy-wta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];T.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e,t){return{id:"copy-wnta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];A.set(n,i)}),o.set(y,b),l.set(y,T),s.set(y,A),ut(o),vt(l),ft(s);var M=h.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:se.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[ue],scheduling_config:r||{},variant_id:e.variantId,question_id:se.ruleId||"",tier_id:y.replace("tier_",""),is_readOnly:!0,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"copy"}});wt(M),Mt(M),bt(function(e){var n=new Map(e);return n.set(y,JSON.parse(JSON.stringify(M))),n});var I=new Map;h.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,f=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,g=null!==(a=null!==(i=null==f?void 0:f.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==f?void 0:f.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,m=null!==(s=null!==(o=null==f?void 0:f.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==f?void 0:f.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;I.set(n,{order_rules:{enabled:g>0,global_min_separation_seconds:Math.floor(g/60)},advertiser_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==f?void 0:f.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==f?void 0:f.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==f?void 0:f.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:U(e.variantType||e.variant_type)})}),Qn(new Map([[y,I]]))}}},[z,ne,ie,te,se,ue,de]),d(function(){if(z){if(console.log("[Accordion Init] editingTier:",te,"focusedVariantIndex:",re),te&&ge(function(n){return e(e({},n),{tiers:[te]})}),gn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void Lt(void 0);if(oe){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),Lt(void 0);var n=(te?J(te):"tier_1").replace(/_/g," ");jt("I want to add a new variant to ".concat(n))}else null!=re?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(re," (from VariantCard)")),Lt(re),ii(function(e){return e+1})):(ne||ie&&ie.length>0)&&(console.log("[Accordion] Opening DEFAULT/1st variant (index 0) for RuleHeader edit"),Lt(0),ii(function(e){return e+1}))}else Lt(void 0)},[z,te,re,ne,ie,oe,gn]),d(function(){z&&le&&ne&&null!==re&&jt("I want to fix the gaps")},[z,le,ne,re]);var Wn={order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1},is_default_enabled:!1},Yn=s(new Map([["tier_1",new Map([[0,Wn]])],["tier_2",new Map([[0,Wn]])]])),Kn=Yn[0],Qn=Yn[1],zn=s(new Set([])),Zn=zn[0],$n=zn[1],Xn=s("");Xn[0];var et=Xn[1],nt=s(""),tt=nt[0],it=nt[1],rt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),at=rt[0],ot=rt[1],lt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),st=lt[0],ut=lt[1],dt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),ct=dt[0],vt=dt[1],_t=s(new Map([["tier_1",new Map],["tier_2",new Map]])),pt=_t[0],ft=_t[1],gt=s([]),mt=gt[0],wt=gt[1],yt=s(new Map),ht=yt[0],bt=yt[1],Tt=s([]),At=Tt[0],Mt=Tt[1],It=s(!1),St=It[0],kt=It[1],Nt=s([]),Ct=Nt[0],xt=Nt[1],Et=s(void 0),Ot=Et[0],Lt=Et[1],Rt=s(""),Dt=Rt[0],jt=Rt[1],Vt=s(null),Pt=Vt[0],Gt=Vt[1],Ft=s([]),qt=Ft[0],Ut=Ft[1],Jt=s([]),Ht=Jt[0],Bt=Jt[1],Wt=s({}),Yt=Wt[0],Kt=Wt[1],Qt=s(new Map),zt=Qt[0],Zt=Qt[1],$t=s(new Set),Xt=$t[0],ei=$t[1],ni=s(0),ti=ni[0],ii=ni[1],ri=s({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),ai=ri[0],oi=ri[1],li=s([]),si=li[0],ui=li[1],di=s(""),ci=di[0],vi=di[1],_i=s({}),pi=_i[0],fi=_i[1],gi=s(!1),mi=gi[0],wi=gi[1],yi=u(null),hi=u(null),bi=u(-1),Ti=u(null);d(function(){Fn.current=mt},[mt]),d(function(){var n=new Set,t=console.warn;return console.warn=function(){for(var i,o=[],l=0;l<arguments.length;l++)o[l]=arguments[l];t.apply(void 0,o);var s=o[0];if("string"==typeof s&&s.includes("Failed to parse JSON for property=")){var u=s.match(/warnId="([^"]+)"/),d=null==u?void 0:u[1];if(d&&n.has(d))return;d&&n.add(d),null===(i=Ti.current)||void 0===i||i.show({severity:"warn",sticky:!1,life:5e3,className:I.toastWarning,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconWarning}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleWarning)},{children:"Parsing Issue"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageWarning)},{children:"The AI response couldn't be parsed correctly. Please try rephrasing your input or retry."}))]}))})}},function(){console.warn=t}},[]);var Ai=s(!1),Mi=Ai[0],Ii=Ai[1],Si=s(!1),ki=Si[0],Ni=Si[1],Ci=s({}),xi=Ci[0],Ei=Ci[1],Oi=s(""),Li=Oi[0],Ri=Oi[1],Di=s(!0),ji=Di[0],Vi=Di[1],Pi=s(!1),Gi=Pi[0],Fi=Pi[1],qi=s(!1),Ui=qi[0],Ji=qi[1],Hi=s(""),Bi=Hi[0],Wi=Hi[1],Yi=s(""),Ki=Yi[0],Qi=Yi[1],zi=s(""),Zi=zi[0],$i=zi[1],Xi=s(null),er=Xi[0],nr=Xi[1],tr=s(null),ir=tr[0],rr=tr[1],ar=s(null),or=ar[0],lr=ar[1],sr=L.getState().user,ur=O(),dr=ur.dispatch,cr=ur.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",mt)},[mt]),d(function(){console.log("isCloseModal AI Response updated:",ji)},[ji]),d(function(){!1===mi?(Ni(!1),Wi(""),Qi("")):(xe(!1),ke(""))},[mi]),d(function(){null!=Ot&&ie&&!ie[Ot]&&nr(null)},[Ot,ie]),d(function(){if(Le&&!De.current){De.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");jt("Save this Learning"),Re(!1),setTimeout(function(){De.current=!1,jt("")},2e3)}},[Le]);var vr=c(function(e,n){ln.some(function(n){return n.id===e})?(Ji(!0),cn(e),pn(n),setTimeout(function(){pn(null),cn(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[ln]),_r=v(function(){var e=Ui&&Qe>0;return console.log("[Loader Debug] showComparison: ".concat(Ui,", activeRequests: ").concat(Qe,", Result: ").concat(e)),e},[Ui,Qe]),pr=c(function(n,t,i){var r,a=void 0!==(null===(r=null==i?void 0:i.target)||void 0===r?void 0:r.value)?i.target.value:i;ut(function(e){var i=new Map(e),r=new Map(i.get(n));return r.set(t,a),i.set(n,r),i}),Ei(function(i){if(i["ruleDescription-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["ruleDescription-".concat(n,"-").concat(t)],r}return i})},[]),fr=c(function(t,i){vt(function(e){var r=new Map(e),a=new Map(r.get(t)),o=a.get(i)||[];return a.set(i,n(n([],o,!0),[{id:Date.now(),text:"",reasoning:""}],!1)),r.set(t,a),r}),Ei(function(n){if(n["whenToApply-".concat(t,"-").concat(i)]){var r=e({},n);return delete r["whenToApply-".concat(t,"-").concat(i)],r}return n})},[]),gr=c(function(e,n,t){vt(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(n)||[];return a.set(n,o.filter(function(e){return e.id!==t})),r.set(e,a),r})},[]),mr=c(function(n,t,i,r){vt(function(a){var o=new Map(a),l=new Map(o.get(n)),s=l.get(t)||[];return l.set(t,s.map(function(n){return String(n.id)===String(i)?e(e({},n),{text:r}):n})),o.set(n,l),o}),Ei(function(i){if(i["whenToApply-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["whenToApply-".concat(n,"-").concat(t)],r}return i})},[]),wr=c(function(e,t){ft(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(t)||[];return a.set(t,n(n([],o,!0),[{id:Date.now(),text:"",reasoning:""}],!1)),r.set(e,a),r})},[]),yr=c(function(e,n,t){ft(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(n)||[];return a.set(n,o.filter(function(e){return e.id!==t})),r.set(e,a),r})},[]),hr=c(function(n,t,i,r){ft(function(a){var o=new Map(a),l=new Map(o.get(n)),s=l.get(t)||[];return l.set(t,s.map(function(n){return String(n.id)===String(i)?e(e({},n),{text:r}):n})),o.set(n,l),o})},[]),br=c(function(e){var n=e.replace(/_/g," ");mn(!0),null==ae||ae(null),Lt(void 0),jt("I want to add a new variant to ".concat(n))},[]),Tr=function(n,t,i){var r="".concat(n,"_").concat(t);console.log("Highlighting ".concat(i," at ").concat(r)),Zt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!0,t))),a}),setTimeout(function(){Zt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!1,t))),a})},1500)},Ar=c(function(n,t){ge(function(i){var r;return e(e({},i),((r={})[n]=t,r))}),Ei(function(t){if(t[n]){var i=e({},t);return delete i[n],i}return t})},[]),Mr=c(function(n,t,i,r){ot(function(e){var r=new Map(e),a=new Map(r.get(n)||new Map),o=a.get(t)||new Set;return o.add(i),a.set(t,o),r.set(n,a),r}),Qn(function(a){var o,l,s,u=new Map(a),d=new Map(u.get(n)||new Map),c=d.get(t)||Wn;switch(i){case"order_rules":case"advertiser_rules":s="boolean"==typeof r?e(e({},c),((o={})[i]=e(e({},c[i]),{enabled:r}),o)):"object"==typeof r&&null!==r?e(e({},c),((l={})[i]={enabled:r.enabled,global_min_separation_seconds:r.global_min_separation_seconds},l)):c;break;case"inventory_rules":s=e(e({},c),{inventory_rules:{respect_inventory_code:"boolean"==typeof r?r:r.respect_inventory_code}});break;case"break_code_rules":s=e(e({},c),{break_code_rules:{respect_break_code:"boolean"==typeof r?r:r.respect_break_code}});break;case"is_default_enabled":s=e(e({},c),{is_default_enabled:"boolean"==typeof r?r:!!r});break;default:s=c}return d.set(t,s),u.set(n,d),u})},[]);d(function(){mi&&(Ji(!1),pn(null),cn(null))},[mi]);var Ir=c(function(n){var t;if(void 0===n&&(n=!1),n||(dr({type:"RESET"}),yi.current=null,wt([]),xt([]),ui([]),fi({}),Ji(!1),Ve.current.clear()),it(""),Ut([]),mn(!1),We.current="",$i(""),rr(null),Bt([]),ge({station:"",tiers:[]}),ze(0),Xe(!1),lr(null),ut(new Map([["tier_1",new Map],["tier_2",new Map]])),vt(new Map([["tier_1",new Map],["tier_2",new Map]])),ft(new Map([["tier_1",new Map],["tier_2",new Map]])),Qn(new Map([["tier_1",new Map([[0,Wn]])],["tier_2",new Map([[0,Wn]])]])),ot(new Map([["tier_1",new Map],["tier_2",new Map]])),et(""),Lt(0),ii(0),ge({station:X,tiers:["Tier 1"]}),n||Kt({}),ot(new Map([["tier_1",new Map],["tier_2",new Map]])),jt(""),oi({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Ei({}),Ri(""),Vi(!0),Ge(null),qe(null),bt(new Map),Mt([]),An(!1),Je(null),hi.current=null,Ye.current=!1,wn.current={},In.current.clear(),Dn.current=null,jn.current=null,Rn(null),ke(""),ye(V),Te(!1),xe(!1),Re(!1),an(null),sn([]),cn(null),pn(null),Nn(null),kt(!1),Gt(null),Wi(""),Qi(""),Ni(!1),$n(new Set),De.current=!1,Be.current.clear(),nn.current=0,en.current=null,Vn.current=null,bi.current=-1,Mn.current=!1,hn.current=!1,ne){ne.ruleTitle&&it(ne.ruleTitle),te&&(ge(function(n){return e(e({},n),{tiers:[te]})}),jn.current=te.toLowerCase().replace(/ /g,"_")),Dn.current=ne.ruleId;var i=null===(t=null==ie?void 0:ie[re||0])||void 0===t?void 0:t.variantId;if(Rn(i||null),ie&&ie.length>0){var r=te?J(te):"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;ie.forEach(function(e,n){s.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,i)}),a.set(r,s),o.set(r,u),l.set(r,d),ut(a),vt(o),ft(l);var c=ie.map(function(e){var n,t,a=null===(n=e.configuration)||void 0===n?void 0:n.scheduling_config;return{variant_type:e.variantType||"variant",title:ne.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:ne.ruleId||"",tier_id:r.replace("tier_",""),is_readOnly:e.variantId!==i,link_id:e.link_id||"",is_enabled:null===(t=e.is_enabled)||void 0===t||t,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});wt(c),Mt(c),bt(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var v=new Map;ie.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,_,p,f,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,w=null!==(s=null!==(o=null==g?void 0:g.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==g?void 0:g.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;v.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:w>0,global_min_separation_seconds:Math.floor(w/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==g?void 0:g.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==g?void 0:g.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(f=null!==(p=null===(_=null==g?void 0:g.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==p?p:null==g?void 0:g.respect_break_code)&&void 0!==f&&f},is_default_enabled:U(e.variantType||e.variant_type)})}),Qn(new Map([[r,v]])),Lt(null!=re?re:0)}}},[dr,X,ne,te,ie,re]),Sr=function(e){if(!e||0===e.length)return"variant 1";var n=e.filter(function(e){var n=e.variant_type||e.variantType||"";return""!==n&&null!==n});return"variant ".concat(n.length+1)},kr=c(function(){console.log("variantIds",qt),Ji(!0)},[qt]),Nr={"Let me connect the dots for you...":function(e){if("string"==typeof e){var n=e.match(/<!--\s*(\{[^}]*"variant_index"[^}]*\})\s*-->/);if(n)try{var t=JSON.parse(n[1]),i=parseInt(t.variant_index,10);if(!isNaN(i)&&i>0){var r=i-1;bi.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),Lt(r),bi.current=r)}}catch(e){console.error("Failed to parse variant_index from HTML comment:",e)}}},"Crafted Instant Learning with C.A.R.E.":function(t){var i,r=N(t),a=N(t,"general_details");console.log("--- [CARE] Staging Initial Structure ---",r);var o=N(t,"critical_gaps");if(console.log("isCriticalGap",o),Xe(!!o),r){if(r.variant_type&&!("is_variant"in r)){var l=null===(i=xr(r.variant_type||"").toLowerCase().match(/^(default_variant|default|variant)/i))||void 0===i?void 0:i[0];r.variant_type=U(l)?"Default":"variant",r.isDefault=U(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?xr(s).toLowerCase().trim().replace(/ /g,"_"):null,d=Boolean(u&&jn.current!==u);if(d&&u){var c=jn.current;console.log("[Tier Switch Detected]",jn.current,"→",u),jn.current=u,Dn.current=null;var v=(Fn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===v&&void 0!==Ot&&(v=Ot),c&&-1!==v&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(v," from ").concat(c)),ut(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),vt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),ft(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),Qn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),wt(function(t){if(!Array.isArray(t))return t;var i=n([],t,!0);return i[v]&&(i[v]=e(e({},i[v]),{scope:[u],tier_id:u.replace("tier_","")})),Fn.current=i,i})),bi.current=-1;var _=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});ge(function(n){return e(e({},n),{tiers:[_]})})}Gt(r),Ge({Updated_Fields_Response:r,General_Response:a}),(null==a?void 0:a.variant_id)&&"new_variant_id"===(null==a?void 0:a.variant_id)&&(a.variant_id=null),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&la(a,r,d),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&Dn.current&&Ln?wt(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)&&n.variant_id===Ln?e(e({},n),r):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===Ln});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Lt(i),ii(function(e){return e+1}),bi.current=i},0),t}):(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&Dn.current&&!Ln?wt(function(t){var i;if(Array.isArray(t)){var a=t.findIndex(function(e){return!0===e.is_new_variant});if(-1!==a)setTimeout(function(){Lt(a),ii(function(e){return e+1}),bi.current=a},0),i=t.map(function(n,t){return t===a?e(e(e({},n),r),{is_new_variant:!0,is_variant:!0}):n});else{var o=t.length;setTimeout(function(){Lt(o),ii(function(e){return e+1}),bi.current=o},0),i=n(n([],t,!0),[e(e({},r),{is_new_variant:!0})],!1)}}else setTimeout(function(){Lt(0),ii(function(e){return e+1}),bi.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return Fn.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(wt([r]),setTimeout(function(){Lt(0),ii(function(e){return e+1}),bi.current=0},0)),void 0!==r.is_user_accepted_risk&&wt(function(t){var i=!(!ne&&!ie),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&ie&&ie.length>0&&(a=ie.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==ne?void 0:ne.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",is_valid:!0,is_readOnly:e.variantId!==Ln,variant_id:e.variantId,tier_id:(null===(t=e.tier)||void 0===t?void 0:t.tier_id)||"1",is_user_accepted_risk:e.is_user_accepted_risk||!1}})),i){var o=er||ir,l=a.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===o||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===o||(null==e?void 0:e.id)&&e.id===o});if(-1===l&&void 0!==Ot&&(l=Ot),-1!==l)return a[l]=e(e({},a[l]),{is_user_accepted_risk:!!r.is_user_accepted_risk}),a}return t})}},"RHS Validation Agent Response":function(t){var i,r,a,o=t;if("string"==typeof t)try{o=JSON.parse(t)}catch(e){o=C(t)}if(qe(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){Gt(function(n){var t=n;if(!t){console.log("⚠️ No staged response found! Constructing fallback from current UI state...");var i=null;if(Array.isArray(mt)){var r=er||ir,a=-1;!(!ne&&!ie)&&r&&(a=mt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===r||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===r||(null==e?void 0:e.id)&&e.id===r})),-1===a&&void 0!==Ot&&(a=Ot),-1!==a&&(i=mt[a])}t=i?e({},i):{wta:"",wnta:""}}return e(e({},t),{wta:t.wta,wnta:t.wnta,is_valid:o.is_valid,conflictingConditions:o.conflictingConditions||[],conflictMarkdown:{},conflict_view:o.conflict_view||{}})});var l=(te||"Tier 1").toLowerCase().replace(/ /g,"_"),s=function(){var e,n=Fn.current;if(Array.isArray(n)&&n.length>0){var t,i=n.findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});if(-1!==i)return console.log("[RHS] Resolved via is_new_variant flag:",i),i;if(Ln)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Ln||(null==e?void 0:e.new_variant_id)===Ln})))return t;if(er)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===er||(null==e?void 0:e.new_variant_id)===er})))return t;var r=null!==(e=null==ie?void 0:ie.length)&&void 0!==e?e:0;if(n.length>r){var a=n.length-1;return console.log("[RHS] Resolved via length diff (new variant appended):",a),a}}var o=void 0!==Ot?Ot:0;return console.log("[RHS] Fallback index used:",o),o}();if(console.log("Resolved variant index for conflict injection:",s),!1===o.is_valid)((null===(i=o.conflictingConditions)||void 0===i?void 0:i.length)||0)>0&&(Ei(function(n){var t=e({},n);return o.conflictingConditions.forEach(function(e){e.condition_wnta&&!e.condition_wta?t["whenNotToApply-".concat(l,"-").concat(s)]=e.reason:t["whenToApply-".concat(l,"-").concat(s)]=e.reason}),t}),Ri("")),o.conflict_view&&((null===(r=o.conflict_view.wta)||void 0===r?void 0:r.length)>0&&vt(function(t){var i=new Map(t),r=new Map(i.get(l)||new Map),a=n([],r.get(s)||[],!0);return o.conflict_view.wta.forEach(function(n){var t=a.findIndex(function(e){return e.text.trim()===n.value});-1!==t?a[t]=e(e({},a[t]),{conflict:n}):a.push({id:"conflict-wta-".concat(Date.now(),"-").concat(Math.random()),text:n.value,conflict:n})}),r.set(s,a),i.set(l,r),i}),(null===(a=o.conflict_view.wnta)||void 0===a?void 0:a.length)>0&&ft(function(t){var i=new Map(t),r=new Map(i.get(l)||new Map),a=n([],r.get(s)||[],!0);return o.conflict_view.wnta.forEach(function(n){var t=a.findIndex(function(e){return e.text.trim()===n.value});-1!==t?a[t]=e(e({},a[t]),{conflict:n}):a.push({id:"conflict-wnta-".concat(Date.now(),"-").concat(Math.random()),text:n.value,conflict:n})}),r.set(s,a),i.set(l,r),i}));else!0===o.is_valid&&(Ei({}),Ri(""),vt(function(n){var t=new Map(n),i=new Map(t.get(l)||new Map),r=i.get(s)||[];return i.set(s,r.map(function(n){return e(e({},n),{conflict:void 0})})),t.set(l,i),t}),ft(function(n){var t=new Map(n),i=new Map(t.get(l)||new Map),r=i.get(s)||[];return i.set(s,r.map(function(n){return e(e({},n),{conflict:void 0})})),t.set(l,i),t}))}},"User Action Execution":function(e){console.log("--- [User Action] Execution ---",e);var n=x(e);(console.log("parsedaction",n),"load"===(null==n?void 0:n.action)&&(null==n?void 0:n.question_id)&&la(n,null),"save"===(null==n?void 0:n.action)&&(null==n?void 0:n.is_save)&&(Vi(!0),Fi(!0)),"discard_rule"===(null==n?void 0:n.action))&&(wt([{variant_id:void 0,rule_description:"",wta:"",wnta:"",variant_type:"variant"}]),Mt([]),Rn(null),Lt(0),ii(0),Nn(null),An(!1),mn(!1),Ut([]),Dn.current=null,it(""),lr(null),Qn(new Map([["tier_1",new Map([[0,Wn]])],["tier_2",new Map([[0,Wn]])]])),ut(new Map([["tier_1",new Map],["tier_2",new Map]])),vt(new Map([["tier_1",new Map],["tier_2",new Map]])),ft(new Map([["tier_1",new Map],["tier_2",new Map]])))},"Validation Agent Response":function(t){var i,r;if(console.log("--- [Validation Agent] Committing Staged Data to UI ---"),console.log("raw data from Validation Agent",t,typeof t),"string"==typeof t){var a=t.match(/<!--\s*```json\s+property="rule_validation_card"\s+([\s\S]*?)```\s*-->/i);if(a&&a[1])try{var o=JSON.parse(a[1].trim()),l=null===(r=null===(i=null==o?void 0:o.validated_rules)||void 0===i?void 0:i[0])||void 0===r?void 0:r.rule_id;l&&(console.log("Setting default comparison ID:",l),cn(l))}catch(e){console.error("Failed to parse rule_validation_card JSON",e)}}var s=N(t,"critical_gaps");console.log("isCriticalGap",s),Xe(!!s);var u="string"==typeof t?x(t):t;console.log("parsed data from Validation Agent",u);var d=E(t);Je(u);var c=!!(null==u?void 0:u.is_variant),v=void 0===(null==u?void 0:u.close_modal)||!!(null==u?void 0:u.close_modal),_=void 0!==(null==u?void 0:u.is_save)&&!!(null==u?void 0:u.is_save);Vi(v),Fi(_);var p=null==u?void 0:u.action,f="string"==typeof(null==u?void 0:u.edit_variant_id)&&u.edit_variant_id.trim()?u.edit_variant_id:"string"==typeof(null==u?void 0:u.set_variant_id)&&u.set_variant_id.trim()?u.set_variant_id:null,g="variant"===p&&c;if((null==u?void 0:u.edit_variant_id)&&!g&&nr(u.edit_variant_id),"edit"!==p&&"edit_current_rule"!==p||!f||rr(f),g&&(nr(null),rr(null)),"discard"===p)return console.log("Action 'discard' received: Resetting UI state but preserving chat."),hn.current=!0,Ir(!0),wt([]),yi.current=null,void(hi.current=null);$i(p);var m=null==u?void 0:u.new_variant_id,w="edit"===(null==u?void 0:u.action)&&(null==u?void 0:u.set_variant_id)&&!ie;(null==u?void 0:u.is_valid)?(Ei({}),Gt(function(t){var i,r,a,o,l,s,d,c,v,_,p,g;if(console.log("⏮️ PREVIOUS Staged Response:",t),!t)return console.warn("⚠️ No previous staged response found"),t;var m=function(e,n){return Object.prototype.hasOwnProperty.call(e||{},n)},w=e(e({},t),u);Array.isArray(null===(i=null==u?void 0:u.condition_result)||void 0===i?void 0:i.when_to_apply)?w.wta=u.condition_result.when_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join(" OR "):m(u,"wta")&&void 0!==(null==u?void 0:u.wta)&&(w.wta=null!==(r=null==u?void 0:u.wta)&&void 0!==r?r:""),Array.isArray(null===(a=null==u?void 0:u.condition_result)||void 0===a?void 0:a.when_not_to_apply)?w.wnta=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join(" OR "):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)&&(w.wnta=null!==(o=null==u?void 0:u.wnta)&&void 0!==o?o:""),console.log("finalData",w),console.log("checking parsed here :",u);var y,h=f;if(Array.isArray(mt)&&h&&(y=h,mt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===y||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===y||(null==e?void 0:e.id)&&e.id===y})),"edit"!==(null==u?void 0:u.action)||!ne&&!ie)return w;console.log("inside edit flow merge");var b=ie||[],T=f,A=T?b.findIndex(function(e){return e.variantId===T||e.variant_id&&e.variant_id===T||e.id&&e.id===T}):-1;if(-1===A&&(null==u?void 0:u.set_variant_id)&&(A=b.findIndex(function(e){return e.variantId===u.set_variant_id||e.variant_id&&e.variant_id===u.set_variant_id||e.id&&e.id===u.set_variant_id})),-1===A&&T&&Array.isArray(mt)&&(A=mt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===T||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===T||(null==e?void 0:e.id)&&e.id===T})),-1!==A){var M,I,S,k=b[A]||(null==mt?void 0:mt[A]),N=(null==k?void 0:k.tier_id)||(null==k?void 0:k.tierId)||"1",C=(null==te?void 0:te.toLowerCase().replace(/ /g,"_"))||"tier_".concat(N);if(bi.current!==A&&(Lt(A),bi.current=A),Array.isArray(null===(l=u.condition_result)||void 0===l?void 0:l.when_to_apply)?M=u.condition_result.when_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wta")&&void 0!==(null==u?void 0:u.wta)?M=null!==(s=null==u?void 0:u.wta)&&void 0!==s?s:"":m(t,"wta")&&void 0!==(null==t?void 0:t.wta)&&(M=null!==(d=null==t?void 0:t.wta)&&void 0!==d?d:""),Array.isArray(null===(c=u.condition_result)||void 0===c?void 0:c.when_not_to_apply)?I=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)?I=null!==(v=null==u?void 0:u.wnta)&&void 0!==v?v:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(I=null!==(_=null==t?void 0:t.wnta)&&void 0!==_?_:""),void 0!==M){var x=xr(M);Er(C,A,M,x,ct,vt,null==u?void 0:u.conflict_view),Tr(C,A,"wta")}if(void 0!==I){var E=xr(I);Er(C,A,I,E,pt,ft,null==u?void 0:u.conflict_view),Tr(C,A,"wnta")}if(m(u,"rule_description")&&void 0!==(null==u?void 0:u.rule_description)?S=null!==(p=null==u?void 0:u.rule_description)&&void 0!==p?p:"":m(t,"rule_description")&&void 0!==(null==t?void 0:t.rule_description)&&(S=null!==(g=null==t?void 0:t.rule_description)&&void 0!==g?g:""),void 0!==S){var O=xr(S);ut(function(e){var n=new Map(e),t=new Map(n.get(C)||new Map);return t.set(A,O),n.set(C,t),n}),Tr(C,A,"ruleDescription")}var L=void 0;m(u,"scheduling_config")&&void 0!==(null==u?void 0:u.scheduling_config)?L=null==u?void 0:u.scheduling_config:m(t,"scheduling_config")&&void 0!==(null==t?void 0:t.scheduling_config)&&(L=null==t?void 0:t.scheduling_config),L&&(Qn(function(e){var n,i,r,a,o,l,s=new Map(e),u=new Map(s.get(C)||new Map);return u.set(A,{order_rules:{enabled:!!(null===(n=L.order_rules)||void 0===n?void 0:n.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=L.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!(null===(r=L.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(a=L.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!(null===(o=L.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!(null===(l=L.break_code_rules)||void 0===l?void 0:l.respect_break_code)},is_default_enabled:"Default"===(null==t?void 0:t.variant_type)||"default_variant"===(null==t?void 0:t.variant_type)||"default"===(null==t?void 0:t.variant_type)}),s.set(C,u),s}),Tr(C,A,"order_enabled"),Tr(C,A,"advertiser_enabled"),Tr(C,A,"respect_inventory_code"),Tr(C,A,"respect_break_code")),wt(function(t){if(!Array.isArray(t)||A<0||!t[A])return t;var i=n([],t,!0),r=e({},i[A]);return void 0!==M&&(r.wta=M),void 0!==I&&(r.wnta=I),void 0!==S&&(r.rule_description=xr(S)),L&&(r.scheduling_config=L),console.log("updated variantxxx",r),i[A]=r,i});var R=null==t?void 0:t.variant_type;R&&wt(function(t){var i=Array.isArray(t)?n([],t,!0):[],r=i.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===T||(null==e?void 0:e.variant_id)&&e.variant_id===(null==u?void 0:u.set_variant_id)||(null==e?void 0:e.variantId)===T});return-1!==r?i[r]=e(e({},i[r]),{variant_type:R}):i[A]=e(e({},i[A]||{}),{variant_type:R,variant_id:T||(null==u?void 0:u.set_variant_id)}),i})}})):console.warn("⚠️ parsed.is_valid is false, not committing to structuredAIResponse"),w||(c?(kt(!0),m&&m!==hi.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),Ni(!0),Wi("Loading a variant"),console.log("reaching here in new variant flow"),Qi("This may take a moment as we update the rule with the new variant."),hi.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(kt(!1),hi.current=null),d&&Ut(d))},"Rule comparison results":function(n){if(Bn){var t=function(n){if("string"!=typeof n)return n;try{var t=Array.from(n.matchAll(/<!--\s*```json\s*([\s\S]*?)\s*```\s*-->/g));if(0===t.length)return JSON.parse(n);var i=t.map(function(e){try{return JSON.parse(e[1].trim())}catch(e){return console.error("Failed to parse JSON block:",e),null}}).filter(function(e){return null!==e});return 1===i.length?i[0]:i.length>1?i.reduce(function(n,t){return e(e({},n),t)},{}):null}catch(e){return console.error("Error extracting JSON:",e),null}}(n);console.log(" LLM Push Comparison Received:",t);var i=t[0].current_rule_details;i&&an({title:i.rule_title||"",description:i.description||"",scope:i.scope||"",wta:Array.isArray(i.wta)?i.wta.join("\n"):i.wta||"",wnta:Array.isArray(i.wnta)?i.wnta.join("\n"):i.wnta||""});var r=t.map(function(e){var n,t,i=e.variant_rule_details||{},r=e.rule_difference_comparison||{},a=i.when_to_apply||i.wta||"",o=i.when_not_to_apply||i.wnta||"";return{id:(null==i?void 0:i.variant_id)&&i.variant_id||(null==i?void 0:i.id)&&i.id||"fallback-id-".concat(Math.random()),title:i.variant_title||i.rule_title||"",description:i.variant_text||i.description||"",scope:i.scope||"",wta:Array.isArray(a)?a.join("\n"):a,wnta:Array.isArray(o)?o.join("\n"):o,similarity:(null===(n=r.summary)||void 0===n?void 0:n.overall_score)||0,summaryText:(null===(t=r.summary)||void 0===t?void 0:t.overall_summary)||"",analysis:{rule_difference_comparison:r},isLoading:!1}});sn(r)}else try{t=n;if("string"==typeof n)try{t=JSON.parse(n)}catch(e){t=x(n)||[]}if(!Array.isArray(t)){if(!t||"object"!=typeof t)return void console.error("[Rule comparison results] Data is not an array:",n);t=[t]}r=t.map(function(e,n){var t,i,r,a,o=null,l=null;if((Array.isArray(e)?e:[e]).forEach(function(e){e&&(e.intent_output&&(o=e.intent_output),e.behaviour_output&&(l=e.behaviour_output))}),"string"==typeof o)try{o=JSON.parse(o)}catch(e){console.error("Failed to parse intent_output",e)}if("string"==typeof l)try{l=JSON.parse(l)}catch(e){console.error("Failed to parse behaviour_output",e)}var s="existing_variant",u="fallback-id-".concat(Math.random()),d=(null==o?void 0:o.documents)||(null==l?void 0:l.documents);if(d){var c=Object.keys(d).find(function(e){return"reference"===d[e].role});c&&(s=c,u="".concat(c,"-").concat(n))}var v="";if((null==o?void 0:o.nodes)&&o.nodes.title){var _=o.nodes.title;(null===(i=null===(t=null==_?void 0:_.comparison_inputs)||void 0===t?void 0:t[s])||void 0===i?void 0:i.content)&&(v=_.comparison_inputs[s].content)}var p="Score";(null==l?void 0:l.final_score)&&(p=l.final_score);var f="Unknown Tier",g=(null===(r=null==d?void 0:d[s])||void 0===r?void 0:r.title)||(null===(a=null==d?void 0:d.existing_variant)||void 0===a?void 0:a.title);return g&&g.includes("|")&&(f=g.split("|")[1].trim()),console.log("Extracted for carousel:",{uniqueId:u,extractedTitle:v,extractedScore:p,extractedScope:f}),{id:u,title:v,similarityScoreText:p,scope:f,intentTreeData:o,behaviorTreeData:l,isLoading:!1}});sn(r)}catch(e){console.error("[Rule comparison results] Critical Handler Error:",e)}}},Cr=function(e){var n=Array.isArray(e)?e.join(" "):String(e||""),t=null==n?void 0:n.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/);return t?t[1]:null},xr=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},Er=function(t,i,r,a,o,l,s){var u;if(void 0!==r){var d=(o.get(t)||new Map).get(i)||[],c=d.map(function(e){return e.text}).join("\n"),v=(null===(u=d[(null==d?void 0:d.length)-1])||void 0===u?void 0:u.reasoning)||"",_=Cr(r)||"";if(""===r&&d.length>0||a.trim()!==c.trim()||_!==v){var p=""===r?{updatedItems:[],newIds:[]}:function(t,i,r){if(!t.trim())return{updatedItems:n([],i,!0),newIds:[]};var a=t.match(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g)||[],o=t.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,""),l=[],s=o.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,function(e){return l.push(e),"__CONFLICT_BLOCK_".concat((null==l?void 0:l.length)-1,"__")}).split(/\s*(?:\r?\n|\\+n)\s*/).map(function(e){return e.trim().replace(/^-\s*/,"")}).filter(Boolean),u=new Map(i.map(function(e){return[e.text,e]})),d=[],c=[],v=Array.isArray(null==r?void 0:r.wta)&&t.includes("wta")?r.wta:Array.isArray(null==r?void 0:r.wnta)?r.wnta:[];return s.forEach(function(n,t){var i=n;i.includes("__CONFLICT_BLOCK_")&&(i=i.replace(/__CONFLICT_BLOCK_(\d+)__/g,function(e,n){return l[parseInt(n)]}));var r=a[t]||"",o=i.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,"").trim(),s=null==v?void 0:v.find(function(e){return e.value===o}),_=u.get(i);if(_)c.push(e(e({},_),{reasoning:r||_.reasoning,conflict:s||_.conflict}));else{var p="new-".concat(Date.now(),"-").concat(t);d.push(p),c.push({id:p,text:i,reasoning:r,conflict:s})}}),{updatedItems:c,newIds:d}}(r,d,s),f=p.updatedItems,g=p.newIds;l(function(e){var n=new Map(e),r=new Map(n.get(t)||new Map);return r.set(i,f),n.set(t,r),n}),(null==g?void 0:g.length)>0&&(ei(function(e){return new Set(n(n([],Array.from(e),!0),g,!0))}),setTimeout(function(){ei(function(e){var n=new Set(e);return g.forEach(function(e){return n.delete(e)}),n})},1500))}}},Or=function(e){return(Array.isArray(e)?e:e?[e]:[]).map(function(e){return String(e).replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/,"").trim().replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})})};d(function(){Dt&&!De.current&&"save this learning"!==Dt.toLowerCase()&&(xe(!1),ke(""),bi.current=null!=Ot?Ot:-1)},[Dt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Gn.current=si,Array.isArray(mt)&&mt.length>0){var c=ci||"local-".concat(Date.now()),v=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],_={},p=yi.current||[];mt.forEach(function(t,i){var r,a;if(t){t.is_readOnly||(nn.current=i);var o=i;if((null==t?void 0:t.variant_id)&&ie)-1!==(l=ie.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if(er&&ie&&1===mt.length){var l;-1!==(l=ie.findIndex(function(e){return e.variantId===er}))&&(o=l)}var s=null!==(r=p[o])&&void 0!==r?r:p[i],u=null!==(a=t.scope)&&void 0!==a?a:null==s?void 0:s.scope,d=Or(u).map(function(e){return e.toLowerCase().replace(/ /g,"_")}),c=d.length>0?d:yn.current.length>0?yn.current:["tier_1"];c.length>0&&(yn.current=c),console.log("prevTierRef.current",yn.current,"targetTiers",c);var f=xr(t.title);f&&f!==xr(null==s?void 0:s.title)&&!t.is_readOnly&&function(e,n,t,i,r,a){var o=xr(i);o&&o!==r&&(Tr(e,n,t),a(o))}("global",0,"ruleTitle",t.title,tt,it),c.forEach(function(r){var a,l,s,u,d,c=null!==(a=p[o])&&void 0!==a?a:p[i],f=!c,g=void 0!==t.rule_description&&null!==t.rule_description,m=xr(t.rule_description),w=(null===(l=st.get(r))||void 0===l?void 0:l.get(o))||"",y=xr(w);g&&(m!==y||""===m&&""!==w)&&(ut(function(e){var n=new Map(e),i=new Map(n.get(r)||new Map);return i.set(o,t.rule_description),n.set(r,i),n}),Tr(r,o,"ruleDescription"));var h=!1===(null==Pt?void 0:Pt.is_valid),b=xr(t.wta),T=xr(null==c?void 0:c.wta),A=(null===(s=ct.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&A.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==T||""===b&&A.length>0||0===A.length&&""!==b)&&(Er(r,o,t.wta,b,ct,vt,null==Pt?void 0:Pt.conflict_view),Tr(r,o,"wta"));var M=xr(t.wnta),I=xr(null==c?void 0:c.wnta),S=(null===(u=pt.get(r))||void 0===u?void 0:u.get(o))||[];if(!(h&&""===M&&S.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(M!==I||""===M&&S.length>0||0===S.length&&""!==M)&&(Er(r,o,t.wnta,M,pt,ft,null==Pt?void 0:Pt.conflict_view),Tr(r,o,"wnta")),t.scheduling_config||f||t.variant_type||t.variantType){var k=t.scheduling_config||{order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1}},N=null==c?void 0:c.scheduling_config,C=null===(d=Kn.get(r))||void 0===d?void 0:d.get(o),x=t.variant_type||t.variantType,E=x?U(x):void 0,O=JSON.stringify(k)!==JSON.stringify(N),L=void 0!==E&&E!==(null==C?void 0:C.is_default_enabled),R=function(n,t){if(!n)return t;if(!t)return n;var i=e({},n);for(var r in t)t[r]&&"object"==typeof t[r]&&!Array.isArray(t[r])?i[r]=e(e({},i[r]||{}),t[r]):i[r]=t[r];return i};if(Kt(function(e){return R(e,k)}),O||L){Kt(function(e){return R(e,k)});var D=function(e,n,t,i){var r,a,o,l,s=[],u=(i.get(e)||new Map).get(n)||{order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1}};return Math.floor(((null===(r=t.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)||0)/60)!==u.order_rules.global_min_separation_seconds&&s.push("config_order_rules"),Math.floor(((null===(a=t.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)!==u.advertiser_rules.global_min_separation_seconds&&s.push("config_advertiser_rules"),!!(null===(o=t.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)!==u.inventory_rules.respect_inventory_code&&s.push("config_inventory_rules"),!!(null===(l=t.break_code_rules)||void 0===l?void 0:l.respect_break_code)!==u.break_code_rules.respect_break_code&&s.push("config_break_code_rules"),!!t.is_default_enabled!=!!u.is_default_enabled&&s.push("config_is_default_enabled"),s}(r,o,k,Kn);D.forEach(function(e){return Tr(r,o,e)}),$n(function(e){return new Set(e).add("config")}),Qn(function(n){var t,i,a,l,s,u,d=new Map(n),c=new Map(d.get(r)||new Map),v=c.get(o)||Wn;return c.set(o,e(e(e(e(e(e({},v),k.order_rules&&{order_rules:{enabled:!!(null===(t=k.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=k.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)}}),k.advertiser_rules&&{advertiser_rules:{enabled:!!(null===(a=k.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(l=k.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)||0)/60)}}),k.inventory_rules&&{inventory_rules:{respect_inventory_code:!!(null===(s=k.inventory_rules)||void 0===s?void 0:s.respect_inventory_code)}}),k.break_code_rules&&{break_code_rules:{respect_break_code:!!(null===(u=k.break_code_rules)||void 0===u?void 0:u.respect_break_code)}}),void 0!==E&&{is_default_enabled:E})),d.set(r,c),d}),ot(function(e){var n=new Map(e),t=new Map(n.get(r)||new Map),i=t.get(o)||new Set;return k.order_rules&&i.add("order_rules"),k.advertiser_rules&&i.add("advertiser_rules"),k.inventory_rules&&i.add("inventory_rules"),k.break_code_rules&&i.add("break_code_rules"),void 0!==E&&i.add("is_default_enabled"),t.set(o,i),n.set(r,t),n})}}var j={ruleTitle:t.title,ruleDescription:t.rule_description,whenToApply:t.wta,whenNotToApply:t.wnta,scopeData:t.scope,configData:t.action};t.is_readOnly||v.forEach(function(e){var n=Cr(j[e]),t="ruleTitle"===e||"scopeData"===e?e:"".concat(e,"_").concat(r);n&&(n!==Pn.current[t]&&(Pn.current[t]=n,qn.current[t]=!0,_[t]={reasoning:n,associatedCitations:[],tier:r,variantIndex:o}))}),t.conflictingConditions&&(Ei(function(n){var i=e({},n);return t.conflictingConditions.forEach(function(e){e.condition_wta&&(i["whenToApply-".concat(r,"-").concat(o)]=e.reason),e.condition_wnta&&(i["whenNotToApply-".concat(r,"-").concat(o)]=e.reason)}),i}),$n(function(e){return new Set(n(n([],Array.from(e),!0),["conditions"],!1))}))})}});var f=-1,g=!(!ne&&!ie),m="edit"===Zi||"edit_current_rule"===Zi,w=function(e,n){return(null==e?void 0:e.variant_id)&&e.variant_id===n||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===n||(null==e?void 0:e.id)&&e.id===n},y=function(e,n){if(!n)return-1;var t=e.find(function(e){return w(e,n)});if(!t)return-1;var i=String((null==t?void 0:t.tier_id)||"");if(!i)return e.findIndex(function(e){return w(e,n)});var r=e.filter(function(e){return String((null==e?void 0:e.tier_id)||"")===i}).findIndex(function(e){return w(e,n)});return-1!==r?r:e.findIndex(function(e){return w(e,n)})};if(g)if(hi.current&&St)-1!==(f=mt.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===hi.current||(null==e?void 0:e.variant_id)&&e.variant_id===hi.current||(null==e?void 0:e.id)&&e.id===hi.current}))&&(hi.current=null);else if(er||ir){var h;(h=er||ir)&&(f=y(mt,h))}else if(oe&&Array.isArray(mt)&&mt.length>0){for(b=mt.length-1;b>=0;b--)if(mt[b]&&!(null===(i=mt[b])||void 0===i?void 0:i.is_readOnly)){f=b;break}}else null==re||yi.current&&0!==yi.current.length||(f=re);else if((h=er||ir||hi.current)&&m&&(f=y(mt,h)),!m&&-1===f&&Array.isArray(mt)&&mt.length>0){for(var b=mt.length-1;b>=0;b--)if(mt[b]&&!(null===(t=mt[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=mt.length-1)}-1!==f&&Ot!==f&&(bi.current===f||Ye.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),Lt(f),bi.current=f));var T=mt[0];if(T){if(T.scope&&JSON.stringify(T.scope)!==JSON.stringify(null===(r=p[0])||void 0===r?void 0:r.scope)&&"copy"!==T.action&&(l=T.scope,s=null===(a=p[0])||void 0===a?void 0:a.scope,u=Or(l),d=s?Or(s):[],ge(function(n){return e(e({},n),{tiers:u})}),u.forEach(function(e){var n=e.trim();d.includes(e)||Tr("global",0,"scope_".concat(n))})),T.scope_rule_set&&T.scope_rule_set!==(null===(o=p[0])||void 0===o?void 0:o.scope_rule_set)){var A=T.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(A)&&(ge(function(n){return e(e({},n),{station:A})}),Tr("global",0,"scope_station"))}T.wtl&&et(T.wtl)}yi.current=mt.map(function(e){return e?(n=e,"function"==typeof(t=null===globalThis||void 0===globalThis?void 0:globalThis.structuredClone)?t(n):JSON.parse(JSON.stringify(n))):e;var n,t}),Object.keys(_).length>0&&(dr({type:"SAVE_CITATIONS",requestId:c,reasoningMap:_,rawCitations:si}),function(e){var n=e.requestId,t=e.keys,i=e.newReasoningMap,r=e.getLatestReasoning,a=e.currentCitations;console.group("%c Citation Audit: ".concat(n," "),"background: #5928ed; color: #fff; font-weight: bold;");var o={};t.forEach(function(e){var n=r(e),t=!!i[e],l=t?a:(null==n?void 0:n.associatedCitations)||[];o[e]={Status:t?"NEW ✅":n?"FALLBACK 🔄":"EMPTY ❌",Source:t?"Current Msg":n?"History":"N/A","Reasoning Preview":t?i[e].reasoning:(null==n?void 0:n.reasoning)||"None","Full Citations":l}}),console.table(o),console.groupEnd()}({requestId:c,keys:Object.keys(_),newReasoningMap:_,getLatestReasoning:cr,currentCitations:si}),oi(function(n){var t=e({},n),i=!1;return Object.keys(_).forEach(function(e){var n=_[e];n.reasoning&&t[e]!==n.reasoning&&(t[e]=n.reasoning,i=!0),n.associatedCitations}),i?t:n}))}},[mt,si,ci]),d(function(){var t=Object.keys(qn.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],si,!0)}),qn.current={},fi(function(n){return e(e({},n),i)})}},[si]);var Lr=function(e){return e.map(function(e){var n;return null===(n=e.match(/\d+/))||void 0===n||n[0],e.replace(/\s+/g,"-"),{name:"Custom",parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==Jn?void 0:Jn.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==ee?void 0:ee.ruleSetDesc)||""}}})},Rr=function(e){var n={};return Object.entries(e).forEach(function(e){var t,i=e[0],r=e[1];if("custom_sep_time_for_entities"===i&&r)n.custom_sep_time_for_entities=r;else if("max_priority_override"===i&&r&&void 0!==r.override_priority_code)n.override_priority_code=r.override_priority_code;else if("advertiser_pair_break_constraint"===i&&r)n.advertiser_pair_break_constraint=r.advertiser_pair_list;else if(r&&"object"==typeof r&&(null===(t=Object.keys(r))||void 0===t?void 0:t.length)>0){var a=i.replace(/_rules$/,""),o=["global_min_separation_seconds","respect_inventory_code","respect_break_code","exemption_advertiser_list","exemption_break_code_list","exemption_priority_code_list","priority_code_list","exemption_product_code_list","condition_advertiser_list","condition_break_code_list","condition_priority_code_list","condition_product_code_list"];Object.entries(r).forEach(function(e){var t=e[0],r=e[1];if(o.includes(t)&&("product_rules"!==i||"global_min_separation_seconds"!==t)){var l="respect_inventory_code"===t||"respect_break_code"===t?t:"".concat(a,"_").concat(t);n[l]=r}})}else if(void 0!==r&&"object"!=typeof r){if("station_guid"===i||"is_default_enabled"===i)return;n[i]=r}}),{config_structure:{scheduling_config:{advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",advertiser_exemption_priority_code_list:"array",advertiser_exemption_product_code_list:"array",advertiser_global_min_separation_seconds:"int",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",break_code_exemption_priority_code_list:"array",break_code_exemption_product_code_list:"array",custom_sep_time_for_entities:"object",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",inventory_exemption_priority_code_list:"array",inventory_exemption_product_code_list:"array",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",order_exemption_product_code_list:"array",order_global_min_separation_seconds:"int",override_priority_code:"str",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",product_exemption_product_code_list:"array",max_priority_override_priority_code_list:"array",max_priority_override_exemption_advertiser_list:"array",max_priority_override_exemption_break_code_list:"array",max_priority_override_exemption_priority_code_list:"array",max_priority_override_exemption_product_code_list:"array",first_in_break_exemption_advertiser_list:"array",first_in_break_exemption_break_code_list:"array",first_in_break_exemption_priority_code_list:"array",first_in_break_exemption_product_code_list:"array",first_in_break_condition_advertiser_list:"array",first_in_break_condition_break_code_list:"array",first_in_break_condition_priority_code_list:"array",first_in_break_condition_product_code_list:"array",advertiser_pair_break_constraint:"array",respect_break_code:"bool",respect_inventory_code:"bool"}},config_data:{scheduling_config:n}}},Dr=function(n,t,i,r){void 0===r&&(r=0);var a=e({},t||{});return n.forEach(function(n,o){var l=n.get(r);l&&l.forEach(function(n){var l,s=t[n]||{},u=i.get(o),d=null==u?void 0:u.get(r),c=null==d?void 0:d[n];if("order_rules"===n||"advertiser_rules"===n){var v=null!==(l=null==c?void 0:c.enabled)&&void 0!==l&&l?60*((null==c?void 0:c.global_min_separation_seconds)||0):0;a[n]=e(e({},s),{global_min_separation_seconds:v})}else a[n]="inventory_rules"===n?e(e({},s),{respect_inventory_code:null==c?void 0:c.respect_inventory_code}):"break_code_rules"===n?e(e({},s),{respect_break_code:null==c?void 0:c.respect_break_code}):"is_default_enabled"===n?null!=c&&c:s})}),a},jr=function(e,n,t){void 0===t&&(t="variantType");var i=null==e?void 0:e[n];if(!i)return{label:Sr(e),isDefault:!1};var r=i[t]||"",a=U(r);return{label:"variant ".concat(n+1),isDefault:a}},Vr=function(e,n){var t=U(e);return{label:"variant ".concat(n+1),isDefault:t}},Pr=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=Kn.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":U(t)?"Default":"Variant"},Gr=function(n,o){return void 0===o&&(o=!1),t(void 0,void 0,void 0,function(){var t,l,s,u,d,c,v,p,g,w,h,b,T,A,S,k,N;return i(this,function(i){switch(i.label){case 0:t=Lr(fe.tiers),l=M.getState().backwardCompatibility,s=nn.current,u=Dr(at,Yt,Kn,s),i.label=1;case 1:return i.trys.push([1,3,,4]),ye(F),ke(""),d=Rr(u),c=m(),v=[],p=[],g=(mt||[])[s]||{},console.log("originalItem check :",g,s),fe.tiers.forEach(function(i){var r,a,o,u,_,f,w,h,b,T,A,M,I,S,k,N=i.toLowerCase().replace(/ /g,"_");p.push(N);var C=(null===(r=st.get(N))||void 0===r?void 0:r.get(s))||"",x=(null===(a=ct.get(N))||void 0===a?void 0:a.get(s))||[],E=(null===(o=pt.get(N))||void 0===o?void 0:o.get(s))||[];if(!1===l){var O=[e(e({},d&&{config:e({master_name:Jn.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:c,variant:xr(C),conditions_whentoapply:x.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:E.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(f=null===(_=null===(u=Kn.get(N))||void 0===u?void 0:u.get(s))||void 0===_?void 0:_.is_default_enabled)||void 0===f||f,tier_id:(null===(w=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===N||e.tier_name.toLowerCase()===N.replace(/_/g,"")}))||void 0===w?void 0:w.tier_id)||"",topic_id:null,scope_id:(null==ee?void 0:ee.ruleSetId)||"",question_title:tt,variantType:Pr(N,s,g.variant_type||g.variantType),instantLearningType:Jn.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:_e,modeId:"019e1e39-2030-7775-8312-0ad525700588"})];v.push(y(O,Jn.ASSISTANT_NAME))}else{O={status:"approved",metadata:e(e({userName:null!==(h=null==sr?void 0:sr.firstname)&&void 0!==h?h:"",userEmailId:null!==(b=null==sr?void 0:sr.email)&&void 0!==b?b:"",llm:D.MODEL,isVariantFlow:!0},d&&{config:e({master_name:D.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:c,variant:xr(C),conditions_whentoapply:x.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:E.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:t[0]||{name:D.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:D.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null===(M=null===(A=null===(T=Kn.get(N))||void 0===T?void 0:T.get(s))||void 0===A?void 0:A.is_default_enabled)||void 0===M||M,tier:{name:i.split(" ").join("").toLowerCase(),tierGroupName:D.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(I=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===N||e.tier_name.toLowerCase()===N.replace(/_/g,"")}))||void 0===I?void 0:I.tier_id)||""},topic:{id:null,value:"".concat(fe.station||X,"RuleSet"),description:null},categories:[{id:null,value:D.CATEGORY,description:D.CATEGORY}],originalQuestion:tt,questionId:n.get(N)||null,variantType:Pr(N,s,g.variant_type||g.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(S=null==sr?void 0:sr.email)&&void 0!==S?S:"",instantLearningType:D.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(k=null==g?void 0:g.is_user_accepted_risk)&&void 0!==k?k:null==Pt?void 0:Pt.is_user_accepted_risk)},isAgentsFeedback:!0})};v.push(y(O,Jn.ASSISTANT_NAME))}}),[4,Promise.all(v)];case 2:return w=i.sent(),Re(!1),console.log("✅ All feedback published:",w),ye(P),Te(!0),h=new Map,w.forEach(function(e,n){var t,i,r=p[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=h.get(r)||[];o.push({id:a,action:"new"}),h.set(r,o)}}),M.getState().setCreatedVariantInfo(Array.from(h.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(S=Ti.current)||void 0===S||S.show({severity:"success",sticky:!1,life:6e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),Ee.current=setTimeout(function(){ji||o?(console.log("Closing modal after save success",{isCloseModal:ji,forceClose:o}),aa()):Ir(!0)},3e3),[3,4];case 3:return b=i.sent(),console.error("❌ Error publishing feedback:",b),Re(!1),ye(G),xe(!0),T=(null===(k=null==b?void 0:b.response)||void 0===k?void 0:k.data)||{},console.log("errorData: ",T),(A="Variant already exists"===(null==T?void 0:T.message))||409===(null==b?void 0:b.status)?ke('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):ke(((null==T?void 0:T.message)||(null==T?void 0:T.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(N=Ti.current)||void 0===N||N.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:A||409===(null==b?void 0:b.status)?"Similar rule already exists. Please update and try again.":(null==T?void 0:T.message)||(null==T?void 0:T.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Fr=function(){return t(void 0,void 0,void 0,function(){var t,o,l,s,u,d,c,v,p,g,w,b,T,A,S,k,N,C,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:t=M.getState().tiers,o=Dr(at,Yt,Kn),l=Rr(o),s=nn.current,u=(mt||[])[s]||{},d=(null==Pt?void 0:Pt.variant_type)||u.variant_type||"",i.label=1;case 1:for(i.trys.push([1,3,,4]),ye(F),ke(""),v=(c=ie||[]).length>0?null===(O=c.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===O?void 0:O.link_id:null,p=(null===(L=fe.tiers[0])||void 0===L?void 0:L.toLowerCase().replace(/ /g,"_"))||"tier_1",g=(null===(R=st.get(p))||void 0===R?void 0:R.size)||c.length,w=n([],c,!0),b=c.length;b<g;b++)w.push({isNewVariant:!0,variantId:m()});return T=[],A=[],S=Lr(fe.tiers),fe.tiers.forEach(function(n){var i=n.toLowerCase().replace(/ /g,"_"),r=t.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=st.get(i),o=ct.get(i),s=pt.get(i);w.forEach(function(t,c){var _,p,f,g,w,b,M,I,k,N,C,x,E,O,L,R,D,j,V,P,G,F,J,H,B,W,Y,K,Q=(null==a?void 0:a.get(c))||t.description||"",z=(null==o?void 0:o.get(c))||[],Z=(null==s?void 0:s.get(c))||[];if(t.isNewVariant){A.push({tierKey:i,payloadType:"new"});var $=Dr(at,Yt,Kn,c),X=Rr($);console.log("variant in save edit add part :",t,u);var te={status:"approved",metadata:e(e({userName:null!==(_=null==sr?void 0:sr.firstname)&&void 0!==_?_:"",userEmailId:null!==(p=null==sr?void 0:sr.email)&&void 0!==p?p:"",llm:Jn.MODEL,isVariantFlow:!0},X&&{config:e({master_name:Jn.CONFIG_MASTER_NAME},X)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:v||m(),variant:xr(Q),conditions_whentoapply:z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:Z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:S[0]||{name:Jn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Jn.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=Kn.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:Jn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(fe.station,"RuleSet"),description:null},categories:[{id:null,value:Jn.CATEGORY,description:Jn.CATEGORY}],originalQuestion:tt,questionId:null==ne?void 0:ne.ruleId,variantType:Pr(i,c,u.variant_type||""),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==sr?void 0:sr.email)&&void 0!==b?b:"",instantLearningType:Jn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(I=null===(M=(mt||[])[c])||void 0===M?void 0:M.is_user_accepted_risk)&&void 0!==I?I:null==Pt?void 0:Pt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",te),T.push(y(te,Jn.ASSISTANT_NAME))}else{A.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var ie=t.variantId===er,re=Pr(i,c,ie?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",re,ie,t,er);var ae={variantId:t.variantId,ruleDesc:(null==ee?void 0:ee.ruleSetDesc)||"",whenToApply:z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:Z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(C=null===(N=null===(k=Kn.get(i))||void 0===k?void 0:k.get(c))||void 0===N?void 0:N.is_default_enabled)&&void 0!==C?C:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||n,tier_priority:null!==(x=null==r?void 0:r.tier_priority)&&void 0!==x?x:null},scope_id:(null==ee?void 0:ee.ruleSetId)||"",description:xr(Q)||"",topic:"".concat(fe.station,"RuleSet"),configuration:(null==l?void 0:l.config_data)||{},tierLinkId:null!=v?v:null,variantType:re,is_user_accepted_risk:!!(null!==(O=null===(E=(mt||[])[c])||void 0===E?void 0:E.is_user_accepted_risk)&&void 0!==O?O:null==t?void 0:t.is_user_accepted_risk),is_enabled:t.is_enabled},oe=(ht.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===t.variantId}),le=!0;if(oe){var se=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ue=se(tt)===se(oe.title),de=se(Q)===se(oe.rule_description),ce=se(ae.whenToApply)===se(oe.wta),ve=se(ae.whenNotToApply)===se(oe.wnta),_e=!!ae.isDefault===U(oe.variant_type),pe=oe.scheduling_config||{},ge=null!==(D=null!==(L=pe.order_global_min_separation_seconds)&&void 0!==L?L:null===(R=pe.order_rules)||void 0===R?void 0:R.global_min_separation_seconds)&&void 0!==D?D:0,me=null!==(P=null!==(j=pe.advertiser_global_min_separation_seconds)&&void 0!==j?j:null===(V=pe.advertiser_rules)||void 0===V?void 0:V.global_min_separation_seconds)&&void 0!==P?P:0,we=null!==(J=null!==(F=null===(G=pe.inventory_rules)||void 0===G?void 0:G.respect_inventory_code)&&void 0!==F?F:pe.respect_inventory_code)&&void 0!==J&&J,ye=null!==(W=null!==(B=null===(H=pe.break_code_rules)||void 0===H?void 0:H.respect_break_code)&&void 0!==B?B:pe.respect_break_code)&&void 0!==W&&W,he=(null===(Y=Kn.get(i))||void 0===Y?void 0:Y.get(c))||Wn,be=he.order_rules.enabled===ge>0&&he.order_rules.global_min_separation_seconds===Math.floor(ge/60)&&he.advertiser_rules.enabled===me>0&&he.advertiser_rules.global_min_separation_seconds===Math.floor(me/60)&&he.inventory_rules.respect_inventory_code===we&&he.break_code_rules.respect_break_code===ye;ue&&de&&ce&&ve&&_e&&be&&(le=!1)}le?(console.log("payloadv (update existing variant)",ae),T.push(h(ae,null!==(K=null==sr?void 0:sr.email)&&void 0!==K?K:""))):(console.log("[saveEditedVariant] No changes for variant ".concat(t.variantId,", skipping API call")),T.push(Promise.resolve({data:{id:t.variantId},skipped:!0})))}})}),[4,Promise.all(T)];case 2:return k=i.sent(),console.log("✅ All variants updated:",k),ye(P),Te(!0),Re(!1),N=new Map,k.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=A[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id);a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data);var o="existing"===r.payloadType?r.existingId:a;if(o&&"string"==typeof o){var l=N.get(r.tierKey)||[];l.push({id:o,action:r.payloadType}),N.set(r.tierKey,l)}}}),M.getState().setCreatedVariantInfo(Array.from(N.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=Ti.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ee.current=setTimeout(function(){aa()},3e3),[3,4];case 3:return C=i.sent(),console.error("❌ Error updating variant:",C),ye(G),xe(!0),Re(!1),x=(null===(j=null==C?void 0:C.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",x),(E="Variant already exists"===(null==x?void 0:x.message))||409===(null==C?void 0:C.status)?ke('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):ke(((null==x?void 0:x.message)||(null==x?void 0:x.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=Ti.current)||void 0===V||V.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:E||409===(null==C?void 0:C.status)?"Similar rule already exists. Please update and try again.":(null==x?void 0:x.message)||(null==x?void 0:x.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},qr=function(){return t(void 0,void 0,void 0,function(){var n,t,o,l,s,u,d,c,v,p,g,w,b,T,A,S,k,N,C,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:n=M.getState().tiers,t=Dr(at,Yt,Kn),o=Rr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),ye(F),ke(""),0===(l=Array.isArray(mt)?mt:[]).length?(console.warn("No variants found to save."),ye(G),[2]):(s=l.filter(function(e){return e.is_new_variant}),u=l.filter(function(e){return!e.is_new_variant&&(null==e?void 0:e.variant_id)}),console.log("[saveLoadAndEditVariant] New: ".concat(s.length,", Existing: ").concat(u.length)),d=u.length>0?null===(R=u.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===R?void 0:R.link_id:null,c=[],v=[],p=[],g=[],w=Lr(fe.tiers),fe.tiers.forEach(function(t){var i=t.toLowerCase().replace(/ /g,"_"),r=n.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=st.get(i),s=ct.get(i),u=pt.get(i);l.forEach(function(n,l){var _,f,y,b,T,A,M,I,S,k,N,C,x,E,O,L,R,D,j,V,P,G,F,J,H,B,W,Y=(null==a?void 0:a.get(l))||n.rule_description||n.description||"",K=(null==s?void 0:s.get(l))||[],Q=(null==u?void 0:u.get(l))||[];if(n.is_new_variant){var z=Dr(at,Yt,Kn,l),Z=Rr(z),$=Pr(i,l,n.variant_type||n.variantType||""),ne={status:"approved",metadata:e(e({userName:null!==(_=null==sr?void 0:sr.firstname)&&void 0!==_?_:"",userEmailId:null!==(f=null==sr?void 0:sr.email)&&void 0!==f?f:"",llm:Jn.MODEL,isVariantFlow:!0},Z&&{config:e({master_name:Jn.CONFIG_MASTER_NAME},Z)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:xr(Y),conditions_whentoapply:K.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:Q.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:w[0]||{name:Jn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Jn.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(T=null===(b=null===(y=Kn.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==T?T:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:Jn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(t.split(" ")[1]||"1"),tier_id:(null==r?void 0:r.tier_id)||""},topic:{id:null,value:"".concat(fe.station||X,"RuleSet"),description:null},categories:[{id:null,value:Jn.CATEGORY,description:Jn.CATEGORY}],originalQuestion:tt,questionId:Dn.current||null,variantType:$,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(A=null==sr?void 0:sr.email)&&void 0!==A?A:"",instantLearningType:Jn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(M=null==n?void 0:n.is_user_accepted_risk)&&void 0!==M?M:null==Pt?void 0:Pt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ne),v.push({payload:ne,tierKey:i}),g.push({tierKey:i})}else if(null==n?void 0:n.variant_id){p.push({tierKey:i,existingId:n.variant_id});var te=(null==n?void 0:n.variant_id)&&n.variant_id===or?(null==Pt?void 0:Pt.variant_type)||n.variant_type||n.variantType||"":n.variant_type||n.variantType||"",ie=($=Pr(i,l,te),{variantId:n.variant_id,ruleDesc:(null==ee?void 0:ee.ruleSetDesc)||"",whenToApply:K.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:Q.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(k=null===(S=null===(I=Kn.get(i))||void 0===I?void 0:I.get(l))||void 0===S?void 0:S.is_default_enabled)&&void 0!==k?k:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||t,tier_priority:null!==(N=null==r?void 0:r.tier_priority)&&void 0!==N?N:null},scope_id:(null==ee?void 0:ee.ruleSetId)||"",description:xr(Y)||"",topic:"".concat(fe.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:$,is_user_accepted_risk:!!(null!==(C=null==n?void 0:n.is_user_accepted_risk)&&void 0!==C?C:null===(x=(mt||[])[l])||void 0===x?void 0:x.is_user_accepted_risk),is_enabled:n.is_enabled}),re=(ht.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===(null==n?void 0:n.variant_id)}),ae=!0;if(re){var oe=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},le=oe(tt)===oe(re.title),se=oe(Y)===oe(re.rule_description),ue=oe(ie.whenToApply)===oe(re.wta),de=oe(ie.whenNotToApply)===oe(re.wnta),ce=!!ie.isDefault===U(re.variant_type),ve=re.scheduling_config||{},_e=null!==(L=null!==(E=ve.order_global_min_separation_seconds)&&void 0!==E?E:null===(O=ve.order_rules)||void 0===O?void 0:O.global_min_separation_seconds)&&void 0!==L?L:0,pe=null!==(j=null!==(R=ve.advertiser_global_min_separation_seconds)&&void 0!==R?R:null===(D=ve.advertiser_rules)||void 0===D?void 0:D.global_min_separation_seconds)&&void 0!==j?j:0,ge=null!==(G=null!==(P=null===(V=ve.inventory_rules)||void 0===V?void 0:V.respect_inventory_code)&&void 0!==P?P:ve.respect_inventory_code)&&void 0!==G&&G,me=null!==(H=null!==(J=null===(F=ve.break_code_rules)||void 0===F?void 0:F.respect_break_code)&&void 0!==J?J:ve.respect_break_code)&&void 0!==H&&H,we=(null===(B=Kn.get(i))||void 0===B?void 0:B.get(l))||Wn,ye=we.order_rules.enabled===_e>0&&we.order_rules.global_min_separation_seconds===Math.floor(_e/60)&&we.advertiser_rules.enabled===pe>0&&we.advertiser_rules.global_min_separation_seconds===Math.floor(pe/60)&&we.inventory_rules.respect_inventory_code===ge&&we.break_code_rules.respect_break_code===me;le&&se&&ue&&de&&ce&&ye&&(ae=!1)}ae?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ie),c.push(h(ie,null!==(W=null==sr?void 0:sr.email)&&void 0!==W?W:""))):(console.log("[saveLoadAndEditVariant] No changes for variant ".concat(n.variant_id,", skipping API call")),c.push(Promise.resolve({data:{id:n.variant_id},skipped:!0})))}})}),[4,Promise.all(c)]);case 2:b=i.sent(),console.log("✅ All existing variants updated:",b),T=[],A=0,S=v,i.label=3;case 3:if(!(A<S.length))return[3,8];k=S[A],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(k.payload,Jn.ASSISTANT_NAME)];case 5:return N=i.sent(),T.push(N),[3,7];case 6:throw C=i.sent(),console.error("❌ Error publishing new variant:",C),C;case 7:return A++,[3,3];case 8:return console.log("✅ All new variants published:",T),x=new Map,b.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=p[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data);var o=r.existingId||a;if(o&&"string"==typeof o){var l=x.get(r.tierKey)||[];l.push({id:o,action:"existing"}),x.set(r.tierKey,l)}}}),T.forEach(function(e,n){var t,i,r=g[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=x.get(r.tierKey)||[];o.push({id:a,action:"new"}),x.set(r.tierKey,o)}}),M.getState().setCreatedVariantInfo(Array.from(x.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),ye(P),Te(!0),Re(!1),Ye.current=!1,null===(D=Ti.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ee.current=setTimeout(function(){aa()},3e3),[3,10];case 9:return E=i.sent(),console.error("❌ Error updating variant:",E),ye(G),xe(!0),Re(!1),O=(null===(j=null==E?void 0:E.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",O),(L="Variant already exists"===(null==O?void 0:O.message))||409===(null==E?void 0:E.status)?ke('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):ke(((null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=Ti.current)||void 0===V||V.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:L||409===(null==E?void 0:E.status)?"Similar rule already exists. Please update and try again.":(null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,10];case 10:return[2]}})})},Ur=function(e){return"string"!=typeof e?e:e.replace(/<conflicting_text>[\s\S]*?<\/conflicting_text>/g,"").replace(/<decision_strength>[\s\S]*?<\/decision_strength>/g,"").replace(/<conflicting_reasoning>[\s\S]*?<\/conflicting_reasoning>/g,"").replace(/<conflicting_gap>[\s\S]*?<\/conflicting_gap>/g,"").replace(/<\/?conflicting>/g,"").trim()};d(function(){Gi&&!mi&&(console.log("isSaveRule received from agent — calling publish APIs directly."),Fi(!1),ne||ie?Fr():!0===Ye.current?qr():t(void 0,void 0,void 0,function(){var e,n,t,r,a,o,l,s;return i(this,function(u){switch(u.label){case 0:u.trys.push([0,5,,6]),ye(F),e=new Map,n=function(n){var t,r,a,o,l,u;return i(this,function(i){switch(i.label){case 0:if(t=n.toLowerCase().replace(/ /g,"_"),r=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return e.set(t,null),[2,"continue"];o={question:tt,orgName:Jn.ORGANIZATION_NAME,scope_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),e.set(t,(null===(s=null==l?void 0:l.data)||void 0===s?void 0:s.id)||null),console.log("✅ Question saved for ".concat(n,":"),l),[3,4];case 3:return u=i.sent(),console.error("❌ Error saving question for ".concat(n,":"),u),e.set(t,null),[3,4];case 4:return[2]}})},t=0,r=fe.tiers,u.label=1;case 1:return t<r.length?(a=r[t],[5,n(a)]):[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return Gr(e),[3,6];case 5:return o=u.sent(),l=new Map,fe.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Gr(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Gi,mi]);var Jr=(null===(B=(null===(H=null==fe?void 0:fe.tiers)||void 0===H?void 0:H[0])||te||"Tier 1")||void 0===B?void 0:B.toLowerCase().replace(/ /g,"_"))||"tier_1",Hr=null!==(W=null!=Ot?Ot:re)&&void 0!==W?W:0,Br=null!=Ot,Wr=Br?null==mt?void 0:mt[Hr]:null,Yr=mt&&(null==mt?void 0:mt.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Ht.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&qt.includes(e.variant_id))})),Kr=(null==Wr?void 0:Wr.new_variant_id)&&Ht.includes(Wr.new_variant_id)?Wr.new_variant_id:(null==Yr?void 0:Yr.new_variant_id)&&Ht.includes(Yr.new_variant_id)?Yr.new_variant_id:"",Qr=!(!ne&&!ie),zr=function(n){var t={},i=fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),r=(null==fe?void 0:fe.station)+"RuleSet",a=i.map(function(e){var n=je.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return n.forEach(function(n,o){var l,s,u,d,c,v,_=(null==n?void 0:n.variant_id)&&n.variant_id||qt[o]||"new_variant_".concat(o),p=(null===(l=n.scope)||void 0===l?void 0:l[0])||Jr,f=st.get(p),g=ct.get(p),m=pt.get(p),w=(null==f?void 0:f.get(o))||n.rule_description||"",y=(null==g?void 0:g.get(o))||[],h=y.length>0?y.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wta||"",b=(null==m?void 0:m.get(o))||[],T=b.length>0?b.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wnta||"",A=Kn.get(p),M=null==A?void 0:A.get(o),I={};M&&Object.keys(M).length>0?I=e(e({},M),{order_rules:e(e({},M.order_rules),{global_min_separation_seconds:60*((null===(s=M.order_rules)||void 0===s?void 0:s.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},M.advertiser_rules),{global_min_separation_seconds:60*((null===(u=M.advertiser_rules)||void 0===u?void 0:u.global_min_separation_seconds)||0)})}):n.scheduling_config&&(I=n.scheduling_config),t[_]={rule_title:tt,variant_description:w,wta:h,ruleset_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a,wnta:T,scope:i,scope_rule_set:r,scheduling_config:I,is_user_accepted_risk:!(null===(v=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(mt||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===v||!v)}}),t};Tn&&console.log("customMetaData.ui_state for addvariant flow",zr(At));var Zr=M(function(e){return e.selectedRuleSetId});He.current={send_metadata_to_orchestrator:!1,default:["scope"],app_mapping_id:_e,save_api_payload:function(){var n;if(!(null===(n=fe.tiers)||void 0===n?void 0:n.length)||!(null==je?void 0:je.length))return[];var t=M.getState().backwardCompatibility,i=nn.current,r=(mt||[])[i]||{},a=Dr(at,Yt,Kn,i),o=Rr(a),l=m(),s=Lr(fe.tiers);return fe.tiers.map(function(n){var a,u,d,c,v,_,p,f,g,w,y,h,b,T,A,M=n.toLowerCase().replace(/ /g,"_"),I=(null===(a=st.get(M))||void 0===a?void 0:a.get(i))||"",S=(null===(u=ct.get(M))||void 0===u?void 0:u.get(i))||[],k=(null===(d=pt.get(M))||void 0===d?void 0:d.get(i))||[];return!1===t?e(e({},o&&{config:e({master_name:Jn.CONFIG_MASTER_NAME},o)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:l,variant:xr(I),conditions_whentoapply:S.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:k.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(_=null===(v=null===(c=Kn.get(M))||void 0===c?void 0:c.get(i))||void 0===v?void 0:v.is_default_enabled)||void 0===_||_,tier_id:(null===(p=je.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===M||e.tier_name.toLowerCase()===M.replace(/_/g,""))}))||void 0===p?void 0:p.tier_id)||"",topic_id:null,scope_id:(null==ee?void 0:ee.ruleSetId)||"",question_title:tt,variantType:Pr(M,i,r.variant_type||r.variantType),instantLearningType:Jn.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:_e,modeId:"019e1e39-2030-7775-8312-0ad525700588"}):{status:"approved",metadata:e(e({userName:null!==(f=null==sr?void 0:sr.firstname)&&void 0!==f?f:"",userEmailId:null!==(g=null==sr?void 0:sr.email)&&void 0!==g?g:"",llm:D.MODEL,isVariantFlow:!0},o&&{config:e({master_name:D.CONFIG_MASTER_NAME},o)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:l,variant:xr(I),conditions_whentoapply:S.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:k.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:s[0]||{name:D.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:D.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null===(h=null===(y=null===(w=Kn.get(M))||void 0===w?void 0:w.get(i))||void 0===y?void 0:y.is_default_enabled)||void 0===h||h,tier_id:(null===(b=je.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===M||e.tier_name.toLowerCase()===M.replace(/_/g,""))}))||void 0===b?void 0:b.tier_id)||"",topic:{id:null,value:"".concat(fe.station||X,"RuleSet"),description:null},categories:[{id:null,value:D.CATEGORY,description:D.CATEGORY}],originalQuestion:tt,questionId:null,variantType:Pr(M,i,r.variant_type||r.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(T=null==sr?void 0:sr.email)&&void 0!==T?T:"",instantLearningType:D.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(A=null==r?void 0:r.is_user_accepted_risk)&&void 0!==A?A:null==Pt?void 0:Pt.is_user_accepted_risk)},isAgentsFeedback:!0})}})}(),ui_state:Qr?{variants:function(){var n={},t=Kn.get(Jr);if(!t)return n;var i=st.get(Jr),r=ct.get(Jr),a=pt.get(Jr),o=fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),l=(null==fe?void 0:fe.station)+"RuleSet",s=o.map(function(e){var n=je.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return t.forEach(function(u,d){var c,v,_,p,f,g,m=null===(c=null==ie?void 0:ie[d])||void 0===c?void 0:c.variantId,w=(mt||[])[d],y=(null==w?void 0:w.new_variant_id)||"",h=m||y||qt[d]||"variant_".concat(d),b=(null==i?void 0:i.get(d))||"",T=((null==r?void 0:r.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",A=((null==a?void 0:a.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",M=t.get(d),I={};M&&Object.keys(M).length>0&&(I=e(e({},M),{order_rules:e(e({},M.order_rules),{global_min_separation_seconds:60*((null===(v=M.order_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},M.advertiser_rules),{global_min_separation_seconds:60*((null===(_=M.advertiser_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)})})),n[h]={rule_title:tt,variant_description:b,wta:T,ruleset_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:s,wnta:A,scope:o,scope_rule_set:l,scheduling_config:I,is_user_accepted_risk:!(null===(g=null!==(p=null==w?void 0:w.is_user_accepted_risk)&&void 0!==p?p:null===(f=null==ie?void 0:ie[d])||void 0===f?void 0:f.is_user_accepted_risk)||void 0===g||!g)}}),n}()}:function(){var n,t,i,r,a,o,l=(mt||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:gn?s=-1:Tn||(s=Hr),{new_current_variant:-1!==s?{rule_title:tt,rule_description:(null===(n=st.get(Jr))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=ct.get(Jr))||void 0===t?void 0:t.get(s))||void 0===i?void 0:i.map(function(e){return Ur(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",wnta:(null===(a=null===(r=pt.get(Jr))||void 0===r?void 0:r.get(s))||void 0===a?void 0:a.map(function(e){return Ur(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",scope:fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),scope_rule_set:(null==fe?void 0:fe.station)+"RuleSet",scheduling_config:function(){var n,t,i,r=null===(n=Kn.get(Jr))||void 0===n?void 0:n.get(s);return r&&0!==Object.keys(r).length?e(e({},r),{order_rules:e(e({},r.order_rules),{global_min_separation_seconds:60*((null===(t=r.order_rules)||void 0===t?void 0:t.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},r.advertiser_rules),{global_min_separation_seconds:60*((null===(i=r.advertiser_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)})}):{}}(),is_user_accepted_risk:!!(null===(o=(mt||[])[s])||void 0===o?void 0:o.is_user_accepted_risk)}:{rule_title:"",rule_description:"",wta:"",wnta:"",scope:[],scope_rule_set:"",scheduling_config:{},is_user_accepted_risk:!1},variants:Tn?zr(At):{}}}(),rule_id_in_current_session:Ct,new_variant_id:function(){var e;return Br&&ne?(null===(e=null==ie?void 0:ie[Hr])||void 0===e?void 0:e.variantId)?null:Kr:null}(),edit_variant_id:Ln,rule_id:Dn.current,backward_compatibility:M.getState().backwardCompatibility,ruleset_id:Zr,current_variants_length:ne?Array.isArray(mt)&&mt.length>0?Math.max((null===(Y=null==ne?void 0:ne.variants)||void 0===Y?void 0:Y.length)||0,mt.length):null===(K=null==ne?void 0:ne.variants)||void 0===K?void 0:K.length:void 0,tiers:M.getState().tiers,authToken:(null==sr?void 0:sr.accessToken)||""};var $r=Sr(At),Xr={ruleTitle:tt,scopeData:fe,variantsByTier:Array.from(Kn.keys()).reduce(function(n,t){var i=Kn.get(t)||new Map,r=st.get(t)||new Map,a=ct.get(t)||new Map,o=pt.get(t)||new Map;return console.log("tier config map",i),n[t]=Array.from(i.keys()).map(function(n,l){var s,u,d=(mt||[])[n]||{};console.log("Original item for tier",t,"index",n,":",d);var c={label:"",isDefault:!1};if(d.is_variant&&!U(d.variant_type))c={label:"",isDefault:!1};else if(ie&&ie.length>0){c=jr(ie,n,"variantType"),console.log("Found matching variant at index",n,":",c);var v=ie[n];if(v){if(!c.label){var _=v.variantType||"",p=U(_);c={label:"variant ".concat(n+1),isDefault:p}}if(v.variantId===er)(g=d.variant_type||(null==Pt?void 0:Pt.variant_type))&&(c=Vr(g,n),console.log("[templateState] editingVariants[".concat(n,']: using CARE variant_type "').concat(g,'" → label "').concat(c.label,'"')));console.log("Computed variant type at index",n,":",c)}else c={label:Sr(ie),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(At&&At.length>0){if(c=jr(At,n,"variant_type"),console.log("Found matching variant at index",n,":",c),Ye.current){var f=At[n];if((null==f?void 0:f.variant_id)===or||(null==f?void 0:f.variantId)===or)(g=d.variant_type||(null==Pt?void 0:Pt.variant_type))&&(c=Vr(g,n),console.log("[templateState] existingVariants[".concat(n,']: load-and-edit using CARE variant_type "').concat(g,'" → label "').concat(c.label,'"')))}}else{var g=d.variant_type||"";c={label:$r,isDefault:U(g)}}console.log("Computed variant data for tier",t,"index",n,":",c);var m=null!==(u=null===(s=i.get(n))||void 0===s?void 0:s.is_default_enabled)&&void 0!==u?u:c.isDefault;console.log("live is default :",m);var w="variant ".concat(l+1),y=r.get(n)||"";return{variantId:qt[n]||d.variant_id||d.variantId,variantType:w,isDefault:m,isModified:d.is_modified,tier:t,index:n,ruleDescription:y.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,""),whenToApplyConditions:(a.get(n)||[]).flatMap(function(n){var t,i=(null===(t=null==n?void 0:n.text)||void 0===t?void 0:t.split(/\s+OR\s+/))||[];return i.length>1?i.map(function(t,i){return e(e({},n),{id:"split-".concat(n.id,"-").concat(i),text:t.trim()})}):[n]}),whenNotToApplyConditions:(o.get(n)||[]).flatMap(function(n){var t,i=(null===(t=null==n?void 0:n.text)||void 0===t?void 0:t.split(/\s+OR\s+/))||[];return i.length>1?i.map(function(t,i){return e(e({},n),{id:"split-".concat(n.id,"-").concat(i),text:t.trim()})}):[n]}),configData:i.get(n)||Wn,isReadOnly:d.is_readOnly||!1,is_variant:d.is_variant||!1,reasoning:{ruleDescription:Cr(y),whenToApply:Cr(d.wta),whenNotToApply:Cr(d.wnta),configData:Cr(d.action)}}}),n},{}),citation:ai,fieldCitations:pi,citations:si};console.log("templateState",Xr);var ea={setRuleTitle:function(n){var t,i=void 0!==(null===(t=null==n?void 0:n.target)||void 0===t?void 0:t.value)?n.target.value:n;it(i),Ei(function(n){if(n.ruleTitle){var t=e({},n);return delete t.ruleTitle,t}return n})},setRuleDescription:function(e,n,t){return pr(e,n,t)},addWhenToApply:function(e,n){return fr(e,n)},removeWhenToApply:function(e,n,t){return gr(e,n,t)},editWhenToApply:function(e,n,t,i){return mr(e,n,t,i)},addWhenNotToApply:function(e,n){return wr(e,n)},removeWhenNotToApply:function(e,n,t){return yr(e,n,t)},editWhenNotToApply:function(e,n,t,i){return hr(e,n,t,i)},addNewVariant:function(e){return br(e)},onScopeChange:Ar,onConfigChange:function(e,n,t,i){return Mr(e,n,t,i)}},na={},ta={};Kn.forEach(function(n,t){na[t]=new Map,ta[t]=new Map,n.forEach(function(n,i){na[t].set(i,[e({key:"order_rules",label:"Order"},n.order_rules),e({key:"advertiser_rules",label:"Advertiser"},n.advertiser_rules)]),ta[t].set(i,[{key:"inventory_rules",label:"Inventory code",enabled:n.inventory_rules.respect_inventory_code},{key:"break_code_rules",label:"Break Code",enabled:n.break_code_rules.respect_break_code},{key:"is_default_enabled",label:"Default Variant",enabled:n.is_default_enabled}])})});var ia=v(function(){if(te){if(1===fe.tiers.length)return 0;var e=fe.tiers.findIndex(function(e){return e.toLowerCase()===te.toLowerCase()});return e>=0?e:0}},[te,fe.tiers]),ra=e(e({defaultOpen:!0,tierOptions:["Tier 1","Tier 2"],stationOptions:[{label:"Global Scope",value:"global"},{label:"Genre Scope",value:"genre"},{label:"Custom Scope",value:"custom"}],separationItemsByTier:na,togglesByTier:ta,highlights:zt,highlightedIds:Xt,openSections:Zn,setOpenSections:$n,setSendMessageInChat:jt,isAiStreaming:mi,defaultTierOpen:ia,defaultVariantOpen:gn?void 0:Ot,autoScrollVariantIndex:gn?void 0:Ot,activeVariantAccordionIndex:gn?void 0:Ot,setActiveVariantAccordionIndex:function(e){Lt(e),null!=e&&setTimeout(function(){mn(!1)},100)},validationErrors:xi,activeEditId:kn,setActiveEditId:Nn,pendingEditId:xn,setPendingEditId:En,conflictReason:Li,usedFor:ne||ie?"Edit":"Create"},Hn),{scrollTrigger:ti});console.log(Ot,"editVariantIndex checking"),d(function(){},[z]),d(function(){if(!mi&&St&&!!(!ne&&!ie)){var e=n([],mt,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||mt.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),Lt(e))}},[mi,St]);var aa=function(){Ee.current&&(clearTimeout(Ee.current),Ee.current=null),Ye.current=!1,Z(),Ir()},oa=function(){var e={};tt.trim()||(e.ruleTitle="Rule Title is required"),fe.station||(e.station="Station Rule Set is required"),fe.tiers&&0!==fe.tiers.length||(e.tiers="At least one tier must be selected");return fe.tiers.map(function(e){return e.toLowerCase().replace(/ /g,"_")}).forEach(function(n){var t=st.get(n),i=ct.get(n),r=Kn.get(n);r&&Array.from(r.keys()).forEach(function(r){var a=null==t?void 0:t.get(r);a&&a.trim()||(e["ruleDescription-".concat(n,"-").concat(r)]="Rule Description is required");var o=null==i?void 0:i.get(r);o&&o.some(function(e){return""!==e.text.trim()})||(e["whenToApply-".concat(n,"-").concat(r)]='At least one "When to apply" condition is required')})}),e};function la(r,a,o){var l,s,u,d,c,v;return void 0===o&&(o=!1),t(this,void 0,void 0,function(){var t,_,p,f,g,m,w,y,h,T,A,M,I,S,k,N,C,x,E,O,L,R,D,j;return i(this,function(i){switch(i.label){case 0:if(t=r.question_id,_=(null==r?void 0:r.variant_id)||null,Mn.current&&Vn.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(Dn.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",_),Rn(_),_?(-1!==(p=(mt||[]).findIndex(function(e){return e.is_new_variant}))&&(Ni(!0),Wi("Removing new variant..."),Qi("Please wait while we remove new variant.")),wt(function(e){if(!Array.isArray(e))return e;var n=e.filter(function(e){return!e.is_new_variant}),t=n.findIndex(function(e){return e.variant_id===_});return-1!==t&&setTimeout(function(){Lt(t),ii(function(e){return e+1}),bi.current=t},0),n}),-1!==p&&((f=function(e){e(function(e){var n=new Map;return e.forEach(function(e,t){var i=new Map(e);i.delete(p);var r=new Map,a=0;i.forEach(function(e){r.set(a,e),a++}),n.set(t,r)}),n})})(Qn),f(ut),f(vt),f(ft),Ut(function(e){var t=n([],e,!0);return t.length>p&&t.splice(p,1),t})),!1===Mn.current&&(Mn.current=!0,-1!==p&&(null===(l=Ti.current)||void 0===l||l.show({severity:"success",summary:"Success",detail:"New variant removed successfully because you selected to edit an existing variant",life:4e3}))),mn(!1)):(console.log("lastLoadedQuestionIdRef.current in else",Dn.current),null===Dn.current&&(Ni(!0),Wi("Adding new variant..."),Qi("Please wait while we add new variant."))),[2];console.log("User Action: fetching fresh variant info for question",t),In.current.clear(),In.current.add(t),Ni(!0),Wi("Loading variants..."),console.log("reaching here in load and edit"),Qi("Please wait while we fetch the latest variant data."),Mn.current=!0,Vn.current=t,i.label=1;case 1:return i.trys.push([1,5,6,10]),g=Date.now(),[4,b(t,(null==ee?void 0:ee.ruleSetId)||"")];case 2:return m=i.sent(),(w=Date.now()-g)<3e3?[4,new Promise(function(e){return setTimeout(e,3e3-w)})]:[3,4];case 3:i.sent(),i.label=4;case 4:return 0===(y=(null===(s=null==m?void 0:m.data)||void 0===s?void 0:s.variants)||[]).length?(console.warn("No variants found for question_id",t),Ni(!1),Wi(""),null===(u=Ti.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(Ye.current=!0,Mn.current=!0,h=(null===(d=null==m?void 0:m.data)||void 0===d?void 0:d.ruleTitle)||"",it(h),T=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,A="tier_1",M="Tier 1",I="1",T&&((S=String(T).match(/(\d+)/))?(k=S[1],I=k,A="tier_".concat(k),M="Tier ".concat(k)):(A=String(T).toLowerCase().trim().replace(/ /g,"_"),M=A.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),I=A.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(M," (ID: ").concat(I,", Key: ").concat(A,")")),ge({station:X||"global",tiers:[M]}),N=function(e,n,t,i,r,a){var o=e.map(function(e){var o,l,s=[t];return{variant_type:e.variantType||"variant",title:n,rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:s,scheduling_config:(null===(o=e.configuration)||void 0===o?void 0:o.scheduling_config)||{},variant_id:e.variantId,question_id:r,tier_id:i,is_readOnly:e.variantId!==a,link_id:e.link_id||"",is_enabled:null===(l=e.is_enabled)||void 0===l||l,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}}),l=new Map,s=new Map,u=new Map,d=new Map;return o.forEach(function(e,n){var t,i,r,a,o,c,v=e.scheduling_config||{};l.set(n,{order_rules:{enabled:!!v.order_global_min_separation_seconds||!!(null===(t=v.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor((v.order_global_min_separation_seconds||(null===(i=v.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!v.advertiser_global_min_separation_seconds||!!(null===(r=v.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor((v.advertiser_global_min_separation_seconds||(null===(a=v.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!v.respect_inventory_code||!!(null===(o=v.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!v.respect_break_code||!!(null===(c=v.break_code_rules)||void 0===c?void 0:c.respect_break_code)},is_default_enabled:U(e.variantType||e.variant_type)}),s.set(n,q(e.rule_description||""));var _=e.wta?e.wta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,_);var p=e.wnta?e.wnta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,p)}),{transformedVariants:o,tierConfigMap:l,tierDescMap:s,tierWtaMap:u,tierWntaMap:d}}(y,h,A,I,t,_),C=N.transformedVariants,x=N.tierConfigMap,E=N.tierDescMap,O=N.tierWtaMap,L=N.tierWntaMap,bt(function(e){var n=new Map(e);return n.set(A,JSON.parse(JSON.stringify(C))),n}),wt(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),C,!0)}),Mt(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),C,!0)}),An(!0),Dn.current=t,Rn(_),R=0,_&&-1!==(D=C.findIndex(function(e){return e.variant_id===_}))&&(R=D),Lt(R),ii(function(e){return e+1}),bi.current=R,mn(!1),Qn(function(e){var n=new Map(e);return n.set(A,x),n}),ut(function(e){var n=new Map(e);return n.set(A,E),n}),vt(function(e){var n=new Map(e);return n.set(A,O),n}),ft(function(e){var n=new Map(e);return n.set(A,L),n}),Ei({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(v=Ti.current)||void 0===v||v.show({severity:"error",summary:"Error",detail:"Failed to fetch variants. Please try again.",life:3e3}),[3,10];case 6:return Mn.current=!1,Ni(!1),Wi(""),Qi(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&Dn.current&&Ln?(console.log("inside edit variant flow",Dn.current,Ln),wt(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)===Ln?e(e({},n),a):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Ln});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Lt(i),ii(function(e){return e+1}),bi.current=i},0),t}),[3,9]):[3,7];case 7:return(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&Dn.current&&!Ln?(console.log("inside add new variant flow",Dn.current,Ln),Ni(!0),Wi("Adding new variant..."),Qi("Please wait while we add new variant."),[4,new Promise(function(e){return setTimeout(e,3e3)})]):[3,9];case 8:i.sent(),Ni(!1),Wi(""),Qi(""),wt(function(t){var i;if(Array.isArray(t)){var r=t.findIndex(function(e){return!0===e.is_new_variant});if(-1!==r)setTimeout(function(){Lt(r),ii(function(e){return e+1}),bi.current=r},0),i=t.map(function(n,t){return t===r?e(e(e({},n),a),{is_new_variant:!0,is_variant:!0}):n});else{var o=t.length;setTimeout(function(){Lt(o),ii(function(e){return e+1}),bi.current=o},0),i=n(n([],t,!0),[e(e({},a),{is_new_variant:!0,is_variant:!0})],!1)}}else setTimeout(function(){Lt(0),ii(0),bi.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return Fn.current=i,i}),i.label=9;case 9:return[7];case 10:return[2]}})})}var sa;return console.log("RuleSet in render",ee),r(o,{children:[a(g,{ref:Ti}),a(S,{open:z,chatAssistantName:Jn.ASSISTANT_NAME,organizationName:Jn.ORGANIZATION_NAME,baseUrl:Jn.BASE_URL,baseWebsocketUrl:Jn.BASE_WEBSOCKET_URL,closeFunction:aa,ThinkingBulbIconComponent:a(j,{}),customSections:a(o,{}),customMetaData:He,chatTitle:ne?Jn.CHAT_TITLE_EDIT.replace("<scope>",(null==ee?void 0:ee.ruleSetName)||""):Jn.CHAT_TITLE.replace("<scope>",(null==ee?void 0:ee.ruleSetName)||""),formTitle:Jn.FORM_TITLE,showSavedMessage:!1,savedMessage:Me,isError:Ce,errorMessage:Se,isSaving:Le,onSave:function(e){console.log("Save this Learning",e);var n=oa();if(Object.keys(n).length>0)return console.log("validation errors",n),void Ei(n);Re(!0),xe(!1),ke("")},showSaveWithoutValidation:!1,onSaveWithoutValidation:function(){return t(void 0,void 0,void 0,function(){var e,n,t,r,a,o,l,s,u;return i(this,function(d){switch(d.label){case 0:return e=oa(),Object.keys(e).length>0?(Ei(e),[2]):(console.log("✅ Bypass Save: Initiated"),ne||ie?[4,Fr()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==Ye.current?[3,4]:[4,qr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),ye(F),n=new Map,t=function(e){var t,r,a,o,l,s;return i(this,function(i){switch(i.label){case 0:if(t=e.toLowerCase().replace(/ /g,"_"),r=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return n.set(t,null),[2,"continue"];o={question:tt,orgName:Jn.ORGANIZATION_NAME,scope_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),n.set(t,(null===(u=null==l?void 0:l.data)||void 0===u?void 0:u.id)||null),[3,4];case 3:return s=i.sent(),console.error("❌ Bypass Save: Error saving question for ".concat(e,":"),s),n.set(t,null),[3,4];case 4:return[2]}})},r=0,a=fe.tiers,d.label=5;case 5:return r<a.length?(o=a[r],[5,t(o)]):[3,8];case 6:d.sent(),d.label=7;case 7:return r++,[3,5];case 8:return[4,Gr(n,!0)];case 9:return d.sent(),[3,11];case 10:return l=d.sent(),ye(G),s=new Map,fe.tiers.forEach(function(e){s.set(e.toLowerCase().replace(/ /g,"_"),null)}),Gr(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:Nr,aiResponse:mt,setAIResponse:wt,width:"90vw",height:"90vh",sendMessageInChat:Dt,template:k.CreateRule,isLoading:we===F,templateProps:{state:Xr,handlers:ea,uiState:ra},setSendMessageInChat:jt,onResetChat:function(){Ir()},onResetRequest:function(){Ii(!0)},isFormDirty:function(){return""!==tt.trim()||""!==fe.station||fe.tiers.length>0||Array.from(st.values()).some(function(e){return Array.from(e.values()).some(function(e){return""!==e.trim()})})||Array.from(ct.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Array.from(pt.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Kn.size>0||at.size>0},initialChatMessage:ne?(sa=ne.ruleTitle||"this rule",null===(Q=null==ie?void 0:ie[null!=re?re:0])||void 0===Q||Q.is_user_accepted_risk,'<p><span>Welcome back! 👋</span>\n <span>I see you want to edit <strong>"'.concat(sa,'."</strong></span>\n <span> <strong>What would you like to update? </strong> </span>\n <span>Describe the change you want to make, and I’ll help you edit it.</span>\n </p>')):null!=ve?ve:Jn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(we===P||be)return!1;if(!tt||""===tt.trim())return!1;if(null!==kn)return!1;if(!fe.station||""===fe.station.trim())return!1;var e=fe.tiers&&fe.tiers.filter(function(e){return e&&""!==e.trim()});if(!e||0===(null==e?void 0:e.length))return!1;for(var n,t=0,i=e.map(function(e){return e.toLowerCase().replace(/ /g,"_")});t<i.length;t++){var r=i[t],a=st.get(r),o=ct.get(r),l=Kn.get(r);if(!l||0===l.size)return!1;for(var s=0,u=Array.from(l.keys());s<u.length;s++){var d=u[s],c=null==a?void 0:a.get(d);if(!c||""===c.trim())return!1;var v=null==o?void 0:o.get(d);if(!(null==v?void 0:v.some(function(e){return e.text&&""!==e.text.trim()})))return!1}}return!(!Kn||0===Kn.size)&&(!(n=function(e){return Array.from(e.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.some(function(e){return!!e.conflict})})})})(ct)&&!n(pt)&&!$e)},setCitations:ui,isLocked:!0,textareaPlaceholder:"Tell me more about this learning..",saveButtonConfig:{label:ne?"Save Changes":"Save Learning",loadingLabel:r("span",e({style:{display:"flex",gap:"5px",alignItems:"center"}},{children:[a(p,{size:20,color:"white",className:"animate-spin"}),a("span",{children:" Saving Changes..."})]}))},setCurrentRequestId:vi,isAiStreaming:mi,setIsAiStreaming:wi,showConfirmReset:Mi,setShowConfirmReset:Ii,confirmReset:function(){Ir(),Ii(!1),aa()},isLoadingVariants:ki,mainText:Bi,subText:Ki,proposedRule:rn,isFetchingComparison:_r,handleOpenComparison:kr,showComparison:Ui,setShowComparison:Ji,variants:ln,onComparisonLinkClick:vr,targetComparisonVariantId:dn,highlightedComparisonField:_n,onAddAsVariant:function(){Ji(!1)},isCopyEnabled:!0,onSubmitFeedback:function(n){return t(void 0,void 0,void 0,function(){var t,r,a,o,l;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),t=e({user_id:null!==(a=null==sr?void 0:sr._id)&&void 0!==a?a:"",user_name:null!==(o=null==sr?void 0:sr.firstname)&&void 0!==o?o:"",user_email:null!==(l=null==sr?void 0:sr.email)&&void 0!==l?l:"",assistant_name:Jn.ASSISTANT_NAME},n),[4,T(t)];case 1:return i.sent(),[3,3];case 2:throw r=i.sent(),console.error("Failed to submit chat feedback",r),r;case 3:return[2]}})})},handleGlobalClickCapture:function(e){null!==kn&&(e.target.closest('[data-edit-id="'.concat(kn,'"]'))||(e.preventDefault(),e.stopPropagation(),En(kn)))},isGlobalEditActive:null!==kn,initialDraftMessage:se?ce:"",socketTimeOutInMilliSeconds:Jn.SOCKET_TIMEOUT})]})};export{H as default,q as filterAgentText};
|
|
1
|
+
import{__assign as e,__spreadArray as n,__awaiter as t,__generator as i}from"tslib";import{jsxs as r,jsx as a,Fragment as o}from"react/jsx-runtime";import l,{useState as s,useRef as u,useEffect as d,useCallback as c,useMemo as v}from"react";import{AlertTriangle as _,Loader as p,Check as f}from"lucide-react";import{Toast as g}from"primereact/toast";import{v4 as m}from"uuid";import{saveInstantLearningQuestion as w,publishFeedback as y,updateVariant as h,fetchRulesByQuestionId as b,submitChatFeedback as T}from"../apis/scopeApis.js";import A from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as I}from"../store/useLearningTemplateStore.js";import M from"../styles/InstantLearningModal.module.css.js";import S from"../../IL-OTJ/ILOTJ.js";import"../../IL-OTJ/_components/atoms/Textarea/Textarea.js";import"../../IL-OTJ/_components/InputDataReasoningCard.js";import"../../IL-OTJ/_components/TooltipComponent.js";import{TemplateList as k}from"../../IL-OTJ/_components/templates/TemplatesMap/templatesMap.js";import{extractAndParseWithProperty as N,parseValidationData as C,extractAndParseResponse as x,extractVariantIds as E}from"../../IL-OTJ/helpers/utils.js";import{useCitations as O}from"../../IL-OTJ/store/CitationsContext.js";import"@mui/material";import"@mui/material/Tooltip";import"react-markdown";import"rehype-raw";import"axios";import"@e-llm-studio/streaming-response";import"@e-llm-studio/watch-me-work";import"../../IL-OTJ/_components/ChatComponents/ChatHeader.js";import"remark-gfm";import"../../IL-OTJ/_components/MarkdownComponents/MarkdownElements.js";import"../../IL-OTJ/_components/CitationLink.js";import"@e-llm-studio/citation";import"@viswa-test/test-citation";import"../LearningManagement.js";import L from"../store/useAuthStore.js";import{useConfigStore as R}from"../store/useConfigStore.js";import D from"../store/useEnvStore.js";import{IL_CONFIG_CONSTANTS as j}from"../config.js";var V=function(){return a("img",{src:A,alt:"Thinking...",width:"20",height:"20"})},P="INITIAL",G="SUCCESS",F="FAILURE",q="IN_PROGRESS",U=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},J=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},H=function(e){return e.toLowerCase().replace(/ /g,"_").replace(/tier(\d+)/i,"tier_$1")},B=function(A){var B,W,Y,K,Q,z,Z=A.isOpen,$=A.onClose,X=A.initialScope,ee=void 0===X?"global":X,ne=A.ruleSet,te=A.editingRule,ie=A.editingTier,re=A.editingVariants,ae=A.focusedVariantIndex,oe=A.setFocusedVariantIndex,le=A.triggerAddVariant,se=A.triggerFixGaps,ue=A.copiedRule,de=A.copiedSourceTier,ce=A.copiedTargetTier,ve=A.initialDraftMessage,_e=A.initialChatMessage,pe=A.applicationIntegrationId;A.modeId;var fe=s({station:ee,tiers:["Tier 1"]}),ge=fe[0],me=fe[1],we=s(P),ye=we[0],he=we[1],be=s(!1),Te=be[0],Ae=be[1],Ie=s("Thank you teacher for teaching me, your rule has been saved successfully."),Me=Ie[0];Ie[1];var Se=s(""),ke=Se[0],Ne=Se[1],Ce=s(!1),xe=Ce[0],Ee=Ce[1],Oe=u(null),Le=s(!1),Re=Le[0],De=Le[1],je=u(!1),Ve=I().tiers,Pe=l.useRef(new Set),Ge=s(null);Ge[0];var Fe=Ge[1],qe=s(null);qe[0];var Ue=qe[1],Je=s(null);Je[0];var He=Je[1],Be=u({}),We=u(new Map),Ye=u(""),Ke=u(!1),Qe=s(0),ze=Qe[0],Ze=Qe[1],$e=s(!1),Xe=$e[0],en=$e[1],nn=u(null),tn=u(0),rn=s(null),an=rn[0],on=rn[1],ln=s([]),sn=ln[0],un=ln[1],dn=s(null),cn=dn[0],vn=dn[1],_n=s(null),pn=_n[0],fn=_n[1],gn=s(!1),mn=gn[0],wn=gn[1],yn=u({}),hn=u([]),bn=u(!1),Tn=s(!1),An=Tn[0],In=Tn[1],Mn=u(!1),Sn=u(new Set),kn=s(null),Nn=kn[0],Cn=kn[1],xn=s(null),En=xn[0],On=xn[1],Ln=s(null),Rn=Ln[0],Dn=Ln[1],jn=u(null),Vn=u(null),Pn=u(null),Gn=u({}),Fn=u([]),qn=u([]),Un=u({}),Jn=R(),Hn=Jn.configuration,Bn=Jn.ilLabels,Wn=I.getState().backwardCompatibility,Yn=D(function(e){return e.rbacConfig});d(function(){Nn||On(null)},[Nn]),d(function(){var e;if(Z&&te){jn.current=te.ruleId;var n=null===(e=null==re?void 0:re[ae||0])||void 0===e?void 0:e.variantId;Dn(n||null)}},[Z,te,re,ae]),d(function(){Z&&me(function(n){return e(e({},n),{station:ee})})},[Z,ee]),d(function(){console.log("triggered",Rn),console.log(yt,"structuredAIResponse"),ht(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Rn&&n.new_variant_id!==Rn})}):n}),St(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Rn&&n.new_variant_id!==Rn})}):n})},[Rn]),d(function(){var n;if(!Z)return kr(),void(bn.current=!1);if(!bn.current){var t=re,i=t&&t.length>0,r=null!=te;if(i||r){if((null==te?void 0:te.ruleTitle)&&at(te.ruleTitle),ie&&(me(function(n){return e(e({},n),{tiers:[ie]})}),Vn.current=ie.toLowerCase().replace(/ /g,"_")),i){var a=ie?H(ie):"tier_1",o=new Map,l=new Map,s=new Map,u=new Map,d=new Map,c=new Map,v=[];t.forEach(function(e,n){u.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];c.set(n,i),v.push(e.variantId||e.variant_id||"")}),o.set(a,u),l.set(a,d),s.set(a,c);var _=null===(n=null==t?void 0:t[ae||0])||void 0===n?void 0:n.variantId,p=t.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:(null==te?void 0:te.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==te?void 0:te.ruleId)||"",tier_id:a.replace("tier_",""),is_readOnly:e.variantId!==_,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});ht(p),ht(p),St(p),At(function(e){var n=new Map(e);return n.set(a,JSON.parse(JSON.stringify(p))),n});var f=new Map;t.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,w=null!==(s=null!==(o=null==g?void 0:g.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==g?void 0:g.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;f.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:w>0,global_min_separation_seconds:Math.floor(w/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==g?void 0:g.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==g?void 0:g.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==g?void 0:g.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==g?void 0:g.respect_break_code)&&void 0!==p&&p},is_default_enabled:J(e.variantType||e.variant_type)})}),Zn(new Map([[a,f]])),ct(o),pt(l),mt(s)}else if(r&&te){var g=te.ruleDesc;if(g&&ct(new Map([["tier_1",new Map([[0,g]])]])),te.whenToApply){var m=te.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wta-".concat(n),text:e,reasoning:""}});pt(new Map([["tier_1",new Map([[0,m]])]]))}if(te.whenNotToApply){var w=te.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wnta-".concat(n),text:e,reasoning:""}});mt(new Map([["tier_1",new Map([[0,w]])]]))}}}else if(ue&&de&&ce){at(ue.ruleTitle||""),me(function(n){return e(e({},n),{tiers:[ce]})}),Vn.current=H(ce);var y=H(de),h=ue.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),T=new Map,A=new Map;h.forEach(function(e,n){b.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e,t){return{id:"copy-wta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];T.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e,t){return{id:"copy-wnta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];A.set(n,i)}),o.set(y,b),l.set(y,T),s.set(y,A),ct(o),pt(l),mt(s);var I=h.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:ue.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[de],scheduling_config:r||{},variant_id:e.variantId,question_id:ue.ruleId||"",tier_id:y.replace("tier_",""),is_readOnly:!0,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"copy"}});ht(I),St(I),At(function(e){var n=new Map(e);return n.set(y,JSON.parse(JSON.stringify(I))),n});var M=new Map;h.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,f=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,g=null!==(a=null!==(i=null==f?void 0:f.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==f?void 0:f.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,m=null!==(s=null!==(o=null==f?void 0:f.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==f?void 0:f.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;M.set(n,{order_rules:{enabled:g>0,global_min_separation_seconds:Math.floor(g/60)},advertiser_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==f?void 0:f.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==f?void 0:f.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==f?void 0:f.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:J(e.variantType||e.variant_type)})}),Zn(new Map([[y,M]]))}}},[Z,te,re,ie,ue,de,ce]),d(function(){if(Z){if(console.log("[Accordion Init] editingTier:",ie,"focusedVariantIndex:",ae),ie&&me(function(n){return e(e({},n),{tiers:[ie]})}),mn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void Dt(void 0);if(le){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),Dt(void 0);var n=(ie?H(ie):"tier_1").replace(/_/g," ");Pt("I want to add a new variant to ".concat(n))}else null!=ae?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(ae," (from VariantCard)")),Dt(ae),ai(function(e){return e+1})):(te||re&&re.length>0)&&(console.log("[Accordion] Opening DEFAULT/1st variant (index 0) for RuleHeader edit"),Dt(0),ai(function(e){return e+1}))}else Dt(void 0)},[Z,ie,ae,te,re,le,mn]),d(function(){Z&&se&&te&&null!==ae&&Pt("I want to fix the gaps")},[Z,se,te,ae]);var Kn={order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1},is_default_enabled:!1},Qn=s(new Map([["tier_1",new Map([[0,Kn]])],["tier_2",new Map([[0,Kn]])]])),zn=Qn[0],Zn=Qn[1],$n=s(new Set([])),Xn=$n[0],et=$n[1],nt=s("");nt[0];var tt=nt[1],it=s(""),rt=it[0],at=it[1],ot=s(new Map([["tier_1",new Map],["tier_2",new Map]])),lt=ot[0],st=ot[1],ut=s(new Map([["tier_1",new Map],["tier_2",new Map]])),dt=ut[0],ct=ut[1],vt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),_t=vt[0],pt=vt[1],ft=s(new Map([["tier_1",new Map],["tier_2",new Map]])),gt=ft[0],mt=ft[1],wt=s([]),yt=wt[0],ht=wt[1],bt=s(new Map),Tt=bt[0],At=bt[1],It=s([]),Mt=It[0],St=It[1],kt=s(!1),Nt=kt[0],Ct=kt[1],xt=s([]),Et=xt[0],Ot=xt[1],Lt=s(void 0),Rt=Lt[0],Dt=Lt[1],jt=s(""),Vt=jt[0],Pt=jt[1],Gt=s(null),Ft=Gt[0],qt=Gt[1],Ut=s([]),Jt=Ut[0],Ht=Ut[1],Bt=s([]),Wt=Bt[0],Yt=Bt[1],Kt=s({}),Qt=Kt[0],zt=Kt[1],Zt=s(new Map),$t=Zt[0],Xt=Zt[1],ei=s(new Set),ni=ei[0],ti=ei[1],ii=s(0),ri=ii[0],ai=ii[1],oi=s({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),li=oi[0],si=oi[1],ui=s([]),di=ui[0],ci=ui[1],vi=s(""),_i=vi[0],pi=vi[1],fi=s({}),gi=fi[0],mi=fi[1],wi=s(!1),yi=wi[0],hi=wi[1],bi=u(null),Ti=u(null),Ai=u(-1),Ii=u(null);d(function(){qn.current=yt},[yt]),d(function(){var n=new Set,t=console.warn;return console.warn=function(){for(var i,o=[],l=0;l<arguments.length;l++)o[l]=arguments[l];t.apply(void 0,o);var s=o[0];if("string"==typeof s&&s.includes("Failed to parse JSON for property=")){var u=s.match(/warnId="([^"]+)"/),d=null==u?void 0:u[1];if(d&&n.has(d))return;d&&n.add(d),null===(i=Ii.current)||void 0===i||i.show({severity:"warn",sticky:!1,life:5e3,className:M.toastWarning,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(_,{className:M.iconWarning}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleWarning)},{children:"Parsing Issue"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageWarning)},{children:"The AI response couldn't be parsed correctly. Please try rephrasing your input or retry."}))]}))})}},function(){console.warn=t}},[]);var Mi=s(!1),Si=Mi[0],ki=Mi[1],Ni=s(!1),Ci=Ni[0],xi=Ni[1],Ei=s({}),Oi=Ei[0],Li=Ei[1],Ri=s(""),Di=Ri[0],ji=Ri[1],Vi=s(!0),Pi=Vi[0],Gi=Vi[1],Fi=s(!1),qi=Fi[0],Ui=Fi[1],Ji=s(!1),Hi=Ji[0],Bi=Ji[1],Wi=s(""),Yi=Wi[0],Ki=Wi[1],Qi=s(""),zi=Qi[0],Zi=Qi[1],$i=s(""),Xi=$i[0],er=$i[1],nr=s(null),tr=nr[0],ir=nr[1],rr=s(null),ar=rr[0],or=rr[1],lr=s(null),sr=lr[0],ur=lr[1],dr=L.getState().user,cr=O(),vr=cr.dispatch,_r=cr.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",yt)},[yt]),d(function(){console.log("isCloseModal AI Response updated:",Pi)},[Pi]),d(function(){!1===yi?(xi(!1),Ki(""),Zi("")):(Ee(!1),Ne(""))},[yi]),d(function(){null!=Rt&&re&&!re[Rt]&&ir(null)},[Rt,re]),d(function(){if(Re&&!je.current){je.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");Pt("Save this Learning"),De(!1),setTimeout(function(){je.current=!1,Pt("")},2e3)}},[Re]);var pr=c(function(e,n){sn.some(function(n){return n.id===e})?(Bi(!0),vn(e),fn(n),setTimeout(function(){fn(null),vn(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[sn]),fr=v(function(){var e=Hi&&ze>0;return console.log("[Loader Debug] showComparison: ".concat(Hi,", activeRequests: ").concat(ze,", Result: ").concat(e)),e},[Hi,ze]),gr=c(function(n,t,i){var r,a=void 0!==(null===(r=null==i?void 0:i.target)||void 0===r?void 0:r.value)?i.target.value:i;ct(function(e){var i=new Map(e),r=new Map(i.get(n));return r.set(t,a),i.set(n,r),i}),Li(function(i){if(i["ruleDescription-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["ruleDescription-".concat(n,"-").concat(t)],r}return i})},[]),mr=c(function(t,i){pt(function(e){var r=new Map(e),a=new Map(r.get(t)),o=a.get(i)||[];return a.set(i,n(n([],o,!0),[{id:Date.now(),text:"",reasoning:""}],!1)),r.set(t,a),r}),Li(function(n){if(n["whenToApply-".concat(t,"-").concat(i)]){var r=e({},n);return delete r["whenToApply-".concat(t,"-").concat(i)],r}return n})},[]),wr=c(function(e,n,t){pt(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(n)||[];return a.set(n,o.filter(function(e){return e.id!==t})),r.set(e,a),r})},[]),yr=c(function(n,t,i,r){pt(function(a){var o=new Map(a),l=new Map(o.get(n)),s=l.get(t)||[];return l.set(t,s.map(function(n){return String(n.id)===String(i)?e(e({},n),{text:r}):n})),o.set(n,l),o}),Li(function(i){if(i["whenToApply-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["whenToApply-".concat(n,"-").concat(t)],r}return i})},[]),hr=c(function(e,t){mt(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(t)||[];return a.set(t,n(n([],o,!0),[{id:Date.now(),text:"",reasoning:""}],!1)),r.set(e,a),r})},[]),br=c(function(e,n,t){mt(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(n)||[];return a.set(n,o.filter(function(e){return e.id!==t})),r.set(e,a),r})},[]),Tr=c(function(n,t,i,r){mt(function(a){var o=new Map(a),l=new Map(o.get(n)),s=l.get(t)||[];return l.set(t,s.map(function(n){return String(n.id)===String(i)?e(e({},n),{text:r}):n})),o.set(n,l),o})},[]),Ar=c(function(e){var n=e.replace(/_/g," ");wn(!0),null==oe||oe(null),Dt(void 0),Pt("I want to add a new variant to ".concat(n))},[]),Ir=function(n,t,i){var r="".concat(n,"_").concat(t);console.log("Highlighting ".concat(i," at ").concat(r)),Xt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!0,t))),a}),setTimeout(function(){Xt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!1,t))),a})},1500)},Mr=c(function(n,t){me(function(i){var r;return e(e({},i),((r={})[n]=t,r))}),Li(function(t){if(t[n]){var i=e({},t);return delete i[n],i}return t})},[]),Sr=c(function(n,t,i,r){st(function(e){var r=new Map(e),a=new Map(r.get(n)||new Map),o=a.get(t)||new Set;return o.add(i),a.set(t,o),r.set(n,a),r}),Zn(function(a){var o,l,s,u=new Map(a),d=new Map(u.get(n)||new Map),c=d.get(t)||Kn;switch(i){case"order_rules":case"advertiser_rules":s="boolean"==typeof r?e(e({},c),((o={})[i]=e(e({},c[i]),{enabled:r}),o)):"object"==typeof r&&null!==r?e(e({},c),((l={})[i]={enabled:r.enabled,global_min_separation_seconds:r.global_min_separation_seconds},l)):c;break;case"inventory_rules":s=e(e({},c),{inventory_rules:{respect_inventory_code:"boolean"==typeof r?r:r.respect_inventory_code}});break;case"break_code_rules":s=e(e({},c),{break_code_rules:{respect_break_code:"boolean"==typeof r?r:r.respect_break_code}});break;case"is_default_enabled":s=e(e({},c),{is_default_enabled:"boolean"==typeof r?r:!!r});break;default:s=c}return d.set(t,s),u.set(n,d),u})},[]);d(function(){yi&&(Bi(!1),fn(null),vn(null))},[yi]);var kr=c(function(n){var t;if(void 0===n&&(n=!1),n||(vr({type:"RESET"}),bi.current=null,ht([]),Ot([]),ci([]),mi({}),Bi(!1),Pe.current.clear()),at(""),Ht([]),wn(!1),Ye.current="",er(""),or(null),Yt([]),me({station:"",tiers:[]}),Ze(0),en(!1),ur(null),ct(new Map([["tier_1",new Map],["tier_2",new Map]])),pt(new Map([["tier_1",new Map],["tier_2",new Map]])),mt(new Map([["tier_1",new Map],["tier_2",new Map]])),Zn(new Map([["tier_1",new Map([[0,Kn]])],["tier_2",new Map([[0,Kn]])]])),st(new Map([["tier_1",new Map],["tier_2",new Map]])),tt(""),Dt(0),ai(0),me({station:ee,tiers:["Tier 1"]}),n||zt({}),st(new Map([["tier_1",new Map],["tier_2",new Map]])),Pt(""),si({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Li({}),ji(""),Gi(!0),Fe(null),Ue(null),At(new Map),St([]),In(!1),He(null),Ti.current=null,Ke.current=!1,yn.current={},Sn.current.clear(),jn.current=null,Vn.current=null,Dn(null),Ne(""),he(P),Ae(!1),Ee(!1),De(!1),on(null),un([]),vn(null),fn(null),Cn(null),Ct(!1),qt(null),Ki(""),Zi(""),xi(!1),et(new Set),je.current=!1,We.current.clear(),tn.current=0,nn.current=null,Pn.current=null,Ai.current=-1,Mn.current=!1,bn.current=!1,te){te.ruleTitle&&at(te.ruleTitle),ie&&(me(function(n){return e(e({},n),{tiers:[ie]})}),Vn.current=ie.toLowerCase().replace(/ /g,"_")),jn.current=te.ruleId;var i=null===(t=null==re?void 0:re[ae||0])||void 0===t?void 0:t.variantId;if(Dn(i||null),re&&re.length>0){var r=ie?H(ie):"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;re.forEach(function(e,n){s.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,i)}),a.set(r,s),o.set(r,u),l.set(r,d),ct(a),pt(o),mt(l);var c=re.map(function(e){var n,t,a=null===(n=e.configuration)||void 0===n?void 0:n.scheduling_config;return{variant_type:e.variantType||"variant",title:te.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:te.ruleId||"",tier_id:r.replace("tier_",""),is_readOnly:e.variantId!==i,link_id:e.link_id||"",is_enabled:null===(t=e.is_enabled)||void 0===t||t,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});ht(c),St(c),At(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var v=new Map;re.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,_,p,f,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,w=null!==(s=null!==(o=null==g?void 0:g.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==g?void 0:g.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;v.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:w>0,global_min_separation_seconds:Math.floor(w/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==g?void 0:g.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==g?void 0:g.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(f=null!==(p=null===(_=null==g?void 0:g.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==p?p:null==g?void 0:g.respect_break_code)&&void 0!==f&&f},is_default_enabled:J(e.variantType||e.variant_type)})}),Zn(new Map([[r,v]])),Dt(null!=ae?ae:0)}}},[vr,ee,te,ie,re,ae]),Nr=function(e){if(!e||0===e.length)return"variant 1";var n=e.filter(function(e){var n=e.variant_type||e.variantType||"";return""!==n&&null!==n});return"variant ".concat(n.length+1)},Cr=c(function(){console.log("variantIds",Jt),Bi(!0)},[Jt]),xr={"Let me connect the dots for you...":function(e){if("string"==typeof e){var n=e.match(/<!--\s*(\{[^}]*"variant_index"[^}]*\})\s*-->/);if(n)try{var t=JSON.parse(n[1]),i=parseInt(t.variant_index,10);if(!isNaN(i)&&i>0){var r=i-1;Ai.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),Dt(r),Ai.current=r)}}catch(e){console.error("Failed to parse variant_index from HTML comment:",e)}}},"Crafted Instant Learning with C.A.R.E.":function(t){var i,r=N(t),a=N(t,"general_details");console.log("--- [CARE] Staging Initial Structure ---",r);var o=N(t,"critical_gaps");if(console.log("isCriticalGap",o),en(!!o),r){if(r.variant_type&&!("is_variant"in r)){var l=null===(i=Or(r.variant_type||"").toLowerCase().match(/^(default_variant|default|variant)/i))||void 0===i?void 0:i[0];r.variant_type=J(l)?"Default":"variant",r.isDefault=J(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?Or(s).toLowerCase().trim().replace(/ /g,"_"):null,d=Boolean(u&&Vn.current!==u);if(d&&u){var c=Vn.current;console.log("[Tier Switch Detected]",Vn.current,"→",u),Vn.current=u,jn.current=null;var v=(qn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===v&&void 0!==Rt&&(v=Rt),c&&-1!==v&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(v," from ").concat(c)),ct(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),pt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),mt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),Zn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),ht(function(t){if(!Array.isArray(t))return t;var i=n([],t,!0);return i[v]&&(i[v]=e(e({},i[v]),{scope:[u],tier_id:u.replace("tier_","")})),qn.current=i,i})),Ai.current=-1;var _=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});me(function(n){return e(e({},n),{tiers:[_]})})}qt(r),Fe({Updated_Fields_Response:r,General_Response:a}),(null==a?void 0:a.variant_id)&&"new_variant_id"===(null==a?void 0:a.variant_id)&&(a.variant_id=null),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&ua(a,r,d),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&jn.current&&Rn?ht(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)&&n.variant_id===Rn?e(e({},n),r):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===Rn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Dt(i),ai(function(e){return e+1}),Ai.current=i},0),t}):(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&jn.current&&!Rn?ht(function(t){var i;if(Array.isArray(t)){var a=t.findIndex(function(e){return!0===e.is_new_variant});if(-1!==a)setTimeout(function(){Dt(a),ai(function(e){return e+1}),Ai.current=a},0),i=t.map(function(n,t){return t===a?e(e(e({},n),r),{is_new_variant:!0,is_variant:!0}):n});else{var o=t.length;setTimeout(function(){Dt(o),ai(function(e){return e+1}),Ai.current=o},0),i=n(n([],t,!0),[e(e({},r),{is_new_variant:!0})],!1)}}else setTimeout(function(){Dt(0),ai(function(e){return e+1}),Ai.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return qn.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(ht([r]),setTimeout(function(){Dt(0),ai(function(e){return e+1}),Ai.current=0},0)),void 0!==r.is_user_accepted_risk&&ht(function(t){var i=!(!te&&!re),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&re&&re.length>0&&(a=re.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==te?void 0:te.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",is_valid:!0,is_readOnly:e.variantId!==Rn,variant_id:e.variantId,tier_id:(null===(t=e.tier)||void 0===t?void 0:t.tier_id)||"1",is_user_accepted_risk:e.is_user_accepted_risk||!1}})),i){var o=tr||ar,l=a.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===o||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===o||(null==e?void 0:e.id)&&e.id===o});if(-1===l&&void 0!==Rt&&(l=Rt),-1!==l)return a[l]=e(e({},a[l]),{is_user_accepted_risk:!!r.is_user_accepted_risk}),a}return t})}},"RHS Validation Agent Response":function(t){var i,r,a,o=t;if("string"==typeof t)try{o=JSON.parse(t)}catch(e){o=C(t)}if(Ue(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){qt(function(n){var t=n;if(!t){console.log("⚠️ No staged response found! Constructing fallback from current UI state...");var i=null;if(Array.isArray(yt)){var r=tr||ar,a=-1;!(!te&&!re)&&r&&(a=yt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===r||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===r||(null==e?void 0:e.id)&&e.id===r})),-1===a&&void 0!==Rt&&(a=Rt),-1!==a&&(i=yt[a])}t=i?e({},i):{wta:"",wnta:""}}return e(e({},t),{wta:t.wta,wnta:t.wnta,is_valid:o.is_valid,conflictingConditions:o.conflictingConditions||[],conflictMarkdown:{},conflict_view:o.conflict_view||{}})});var l=(ie||"Tier 1").toLowerCase().replace(/ /g,"_"),s=function(){var e,n=qn.current;if(Array.isArray(n)&&n.length>0){var t,i=n.findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});if(-1!==i)return console.log("[RHS] Resolved via is_new_variant flag:",i),i;if(Rn)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Rn||(null==e?void 0:e.new_variant_id)===Rn})))return t;if(tr)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===tr||(null==e?void 0:e.new_variant_id)===tr})))return t;var r=null!==(e=null==re?void 0:re.length)&&void 0!==e?e:0;if(n.length>r){var a=n.length-1;return console.log("[RHS] Resolved via length diff (new variant appended):",a),a}}var o=void 0!==Rt?Rt:0;return console.log("[RHS] Fallback index used:",o),o}();if(console.log("Resolved variant index for conflict injection:",s),!1===o.is_valid)((null===(i=o.conflictingConditions)||void 0===i?void 0:i.length)||0)>0&&(Li(function(n){var t=e({},n);return o.conflictingConditions.forEach(function(e){e.condition_wnta&&!e.condition_wta?t["whenNotToApply-".concat(l,"-").concat(s)]=e.reason:t["whenToApply-".concat(l,"-").concat(s)]=e.reason}),t}),ji("")),o.conflict_view&&((null===(r=o.conflict_view.wta)||void 0===r?void 0:r.length)>0&&pt(function(t){var i=new Map(t),r=new Map(i.get(l)||new Map),a=n([],r.get(s)||[],!0);return o.conflict_view.wta.forEach(function(n){var t=a.findIndex(function(e){return e.text.trim()===n.value});-1!==t?a[t]=e(e({},a[t]),{conflict:n}):a.push({id:"conflict-wta-".concat(Date.now(),"-").concat(Math.random()),text:n.value,conflict:n})}),r.set(s,a),i.set(l,r),i}),(null===(a=o.conflict_view.wnta)||void 0===a?void 0:a.length)>0&&mt(function(t){var i=new Map(t),r=new Map(i.get(l)||new Map),a=n([],r.get(s)||[],!0);return o.conflict_view.wnta.forEach(function(n){var t=a.findIndex(function(e){return e.text.trim()===n.value});-1!==t?a[t]=e(e({},a[t]),{conflict:n}):a.push({id:"conflict-wnta-".concat(Date.now(),"-").concat(Math.random()),text:n.value,conflict:n})}),r.set(s,a),i.set(l,r),i}));else!0===o.is_valid&&(Li({}),ji(""),pt(function(n){var t=new Map(n),i=new Map(t.get(l)||new Map),r=i.get(s)||[];return i.set(s,r.map(function(n){return e(e({},n),{conflict:void 0})})),t.set(l,i),t}),mt(function(n){var t=new Map(n),i=new Map(t.get(l)||new Map),r=i.get(s)||[];return i.set(s,r.map(function(n){return e(e({},n),{conflict:void 0})})),t.set(l,i),t}))}},"User Action Execution":function(e){console.log("--- [User Action] Execution ---",e);var n=x(e);(console.log("parsedaction",n),"load"===(null==n?void 0:n.action)&&(null==n?void 0:n.question_id)&&ua(n,null),"save"===(null==n?void 0:n.action)&&(null==n?void 0:n.is_save)&&(Gi(!0),Ui(!0)),"discard_rule"===(null==n?void 0:n.action))&&(ht([{variant_id:void 0,rule_description:"",wta:"",wnta:"",variant_type:"variant"}]),St([]),Dn(null),Dt(0),ai(0),Cn(null),In(!1),wn(!1),Ht([]),jn.current=null,at(""),ur(null),Zn(new Map([["tier_1",new Map([[0,Kn]])],["tier_2",new Map([[0,Kn]])]])),ct(new Map([["tier_1",new Map],["tier_2",new Map]])),pt(new Map([["tier_1",new Map],["tier_2",new Map]])),mt(new Map([["tier_1",new Map],["tier_2",new Map]])))},"Validation Agent Response":function(t){var i,r;if(console.log("--- [Validation Agent] Committing Staged Data to UI ---"),console.log("raw data from Validation Agent",t,typeof t),"string"==typeof t){var a=t.match(/<!--\s*```json\s+property="rule_validation_card"\s+([\s\S]*?)```\s*-->/i);if(a&&a[1])try{var o=JSON.parse(a[1].trim()),l=null===(r=null===(i=null==o?void 0:o.validated_rules)||void 0===i?void 0:i[0])||void 0===r?void 0:r.rule_id;l&&(console.log("Setting default comparison ID:",l),vn(l))}catch(e){console.error("Failed to parse rule_validation_card JSON",e)}}var s=N(t,"critical_gaps");console.log("isCriticalGap",s),en(!!s);var u="string"==typeof t?x(t):t;console.log("parsed data from Validation Agent",u);var d=E(t);He(u);var c=!!(null==u?void 0:u.is_variant),v=void 0===(null==u?void 0:u.close_modal)||!!(null==u?void 0:u.close_modal),_=void 0!==(null==u?void 0:u.is_save)&&!!(null==u?void 0:u.is_save);Gi(v),Ui(_);var p=null==u?void 0:u.action,f="string"==typeof(null==u?void 0:u.edit_variant_id)&&u.edit_variant_id.trim()?u.edit_variant_id:"string"==typeof(null==u?void 0:u.set_variant_id)&&u.set_variant_id.trim()?u.set_variant_id:null,g="variant"===p&&c;if((null==u?void 0:u.edit_variant_id)&&!g&&ir(u.edit_variant_id),"edit"!==p&&"edit_current_rule"!==p||!f||or(f),g&&(ir(null),or(null)),"discard"===p)return console.log("Action 'discard' received: Resetting UI state but preserving chat."),bn.current=!0,kr(!0),ht([]),bi.current=null,void(Ti.current=null);er(p);var m=null==u?void 0:u.new_variant_id,w="edit"===(null==u?void 0:u.action)&&(null==u?void 0:u.set_variant_id)&&!re;(null==u?void 0:u.is_valid)?(Li({}),qt(function(t){var i,r,a,o,l,s,d,c,v,_,p,g;if(console.log("⏮️ PREVIOUS Staged Response:",t),!t)return console.warn("⚠️ No previous staged response found"),t;var m=function(e,n){return Object.prototype.hasOwnProperty.call(e||{},n)},w=e(e({},t),u);Array.isArray(null===(i=null==u?void 0:u.condition_result)||void 0===i?void 0:i.when_to_apply)?w.wta=u.condition_result.when_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join(" OR "):m(u,"wta")&&void 0!==(null==u?void 0:u.wta)&&(w.wta=null!==(r=null==u?void 0:u.wta)&&void 0!==r?r:""),Array.isArray(null===(a=null==u?void 0:u.condition_result)||void 0===a?void 0:a.when_not_to_apply)?w.wnta=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join(" OR "):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)&&(w.wnta=null!==(o=null==u?void 0:u.wnta)&&void 0!==o?o:""),console.log("finalData",w),console.log("checking parsed here :",u);var y,h=f;if(Array.isArray(yt)&&h&&(y=h,yt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===y||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===y||(null==e?void 0:e.id)&&e.id===y})),"edit"!==(null==u?void 0:u.action)||!te&&!re)return w;console.log("inside edit flow merge");var b=re||[],T=f,A=T?b.findIndex(function(e){return e.variantId===T||e.variant_id&&e.variant_id===T||e.id&&e.id===T}):-1;if(-1===A&&(null==u?void 0:u.set_variant_id)&&(A=b.findIndex(function(e){return e.variantId===u.set_variant_id||e.variant_id&&e.variant_id===u.set_variant_id||e.id&&e.id===u.set_variant_id})),-1===A&&T&&Array.isArray(yt)&&(A=yt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===T||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===T||(null==e?void 0:e.id)&&e.id===T})),-1!==A){var I,M,S,k=b[A]||(null==yt?void 0:yt[A]),N=(null==k?void 0:k.tier_id)||(null==k?void 0:k.tierId)||"1",C=(null==ie?void 0:ie.toLowerCase().replace(/ /g,"_"))||"tier_".concat(N);if(Ai.current!==A&&(Dt(A),Ai.current=A),Array.isArray(null===(l=u.condition_result)||void 0===l?void 0:l.when_to_apply)?I=u.condition_result.when_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wta")&&void 0!==(null==u?void 0:u.wta)?I=null!==(s=null==u?void 0:u.wta)&&void 0!==s?s:"":m(t,"wta")&&void 0!==(null==t?void 0:t.wta)&&(I=null!==(d=null==t?void 0:t.wta)&&void 0!==d?d:""),Array.isArray(null===(c=u.condition_result)||void 0===c?void 0:c.when_not_to_apply)?M=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)?M=null!==(v=null==u?void 0:u.wnta)&&void 0!==v?v:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(M=null!==(_=null==t?void 0:t.wnta)&&void 0!==_?_:""),void 0!==I){var x=Or(I);Lr(C,A,I,x,_t,pt,null==u?void 0:u.conflict_view),Ir(C,A,"wta")}if(void 0!==M){var E=Or(M);Lr(C,A,M,E,gt,mt,null==u?void 0:u.conflict_view),Ir(C,A,"wnta")}if(m(u,"rule_description")&&void 0!==(null==u?void 0:u.rule_description)?S=null!==(p=null==u?void 0:u.rule_description)&&void 0!==p?p:"":m(t,"rule_description")&&void 0!==(null==t?void 0:t.rule_description)&&(S=null!==(g=null==t?void 0:t.rule_description)&&void 0!==g?g:""),void 0!==S){var O=Or(S);ct(function(e){var n=new Map(e),t=new Map(n.get(C)||new Map);return t.set(A,O),n.set(C,t),n}),Ir(C,A,"ruleDescription")}var L=void 0;m(u,"scheduling_config")&&void 0!==(null==u?void 0:u.scheduling_config)?L=null==u?void 0:u.scheduling_config:m(t,"scheduling_config")&&void 0!==(null==t?void 0:t.scheduling_config)&&(L=null==t?void 0:t.scheduling_config),L&&(Zn(function(e){var n,i,r,a,o,l,s=new Map(e),u=new Map(s.get(C)||new Map);return u.set(A,{order_rules:{enabled:!!(null===(n=L.order_rules)||void 0===n?void 0:n.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=L.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!(null===(r=L.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(a=L.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!(null===(o=L.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!(null===(l=L.break_code_rules)||void 0===l?void 0:l.respect_break_code)},is_default_enabled:"Default"===(null==t?void 0:t.variant_type)||"default_variant"===(null==t?void 0:t.variant_type)||"default"===(null==t?void 0:t.variant_type)}),s.set(C,u),s}),Ir(C,A,"order_enabled"),Ir(C,A,"advertiser_enabled"),Ir(C,A,"respect_inventory_code"),Ir(C,A,"respect_break_code")),ht(function(t){if(!Array.isArray(t)||A<0||!t[A])return t;var i=n([],t,!0),r=e({},i[A]);return void 0!==I&&(r.wta=I),void 0!==M&&(r.wnta=M),void 0!==S&&(r.rule_description=Or(S)),L&&(r.scheduling_config=L),console.log("updated variantxxx",r),i[A]=r,i});var R=null==t?void 0:t.variant_type;R&&ht(function(t){var i=Array.isArray(t)?n([],t,!0):[],r=i.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===T||(null==e?void 0:e.variant_id)&&e.variant_id===(null==u?void 0:u.set_variant_id)||(null==e?void 0:e.variantId)===T});return-1!==r?i[r]=e(e({},i[r]),{variant_type:R}):i[A]=e(e({},i[A]||{}),{variant_type:R,variant_id:T||(null==u?void 0:u.set_variant_id)}),i})}})):console.warn("⚠️ parsed.is_valid is false, not committing to structuredAIResponse"),w||(c?(Ct(!0),m&&m!==Ti.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),xi(!0),Ki("Loading a variant"),console.log("reaching here in new variant flow"),Zi("This may take a moment as we update the rule with the new variant."),Ti.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(Ct(!1),Ti.current=null),d&&Ht(d))},"Rule comparison results":function(n){if(Wn){var t=function(n){if("string"!=typeof n)return n;try{var t=Array.from(n.matchAll(/<!--\s*```json\s*([\s\S]*?)\s*```\s*-->/g));if(0===t.length)return JSON.parse(n);var i=t.map(function(e){try{return JSON.parse(e[1].trim())}catch(e){return console.error("Failed to parse JSON block:",e),null}}).filter(function(e){return null!==e});return 1===i.length?i[0]:i.length>1?i.reduce(function(n,t){return e(e({},n),t)},{}):null}catch(e){return console.error("Error extracting JSON:",e),null}}(n);console.log(" LLM Push Comparison Received:",t);var i=t[0].current_rule_details;i&&on({title:i.rule_title||"",description:i.description||"",scope:i.scope||"",wta:Array.isArray(i.wta)?i.wta.join("\n"):i.wta||"",wnta:Array.isArray(i.wnta)?i.wnta.join("\n"):i.wnta||""});var r=t.map(function(e){var n,t,i=e.variant_rule_details||{},r=e.rule_difference_comparison||{},a=i.when_to_apply||i.wta||"",o=i.when_not_to_apply||i.wnta||"";return{id:(null==i?void 0:i.variant_id)&&i.variant_id||(null==i?void 0:i.id)&&i.id||"fallback-id-".concat(Math.random()),title:i.variant_title||i.rule_title||"",description:i.variant_text||i.description||"",scope:i.scope||"",wta:Array.isArray(a)?a.join("\n"):a,wnta:Array.isArray(o)?o.join("\n"):o,similarity:(null===(n=r.summary)||void 0===n?void 0:n.overall_score)||0,summaryText:(null===(t=r.summary)||void 0===t?void 0:t.overall_summary)||"",analysis:{rule_difference_comparison:r},isLoading:!1}});un(r)}else try{t=n;if("string"==typeof n)try{t=JSON.parse(n)}catch(e){t=x(n)||[]}if(!Array.isArray(t)){if(!t||"object"!=typeof t)return void console.error("[Rule comparison results] Data is not an array:",n);t=[t]}r=t.map(function(e,n){var t,i,r,a,o=null,l=null;if((Array.isArray(e)?e:[e]).forEach(function(e){e&&(e.intent_output&&(o=e.intent_output),e.behaviour_output&&(l=e.behaviour_output))}),"string"==typeof o)try{o=JSON.parse(o)}catch(e){console.error("Failed to parse intent_output",e)}if("string"==typeof l)try{l=JSON.parse(l)}catch(e){console.error("Failed to parse behaviour_output",e)}var s="existing_variant",u="fallback-id-".concat(Math.random()),d=(null==o?void 0:o.documents)||(null==l?void 0:l.documents);if(d){var c=Object.keys(d).find(function(e){return"reference"===d[e].role});c&&(s=c,u="".concat(c,"-").concat(n))}var v="";if((null==o?void 0:o.nodes)&&o.nodes.title){var _=o.nodes.title;(null===(i=null===(t=null==_?void 0:_.comparison_inputs)||void 0===t?void 0:t[s])||void 0===i?void 0:i.content)&&(v=_.comparison_inputs[s].content)}var p="Score";(null==l?void 0:l.final_score)&&(p=l.final_score);var f="Unknown Tier",g=(null===(r=null==d?void 0:d[s])||void 0===r?void 0:r.title)||(null===(a=null==d?void 0:d.existing_variant)||void 0===a?void 0:a.title);return g&&g.includes("|")&&(f=g.split("|")[1].trim()),console.log("Extracted for carousel:",{uniqueId:u,extractedTitle:v,extractedScore:p,extractedScope:f}),{id:u,title:v,similarityScoreText:p,scope:f,intentTreeData:o,behaviorTreeData:l,isLoading:!1}});un(r)}catch(e){console.error("[Rule comparison results] Critical Handler Error:",e)}}},Er=function(e){var n=Array.isArray(e)?e.join(" "):String(e||""),t=null==n?void 0:n.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/);return t?t[1]:null},Or=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},Lr=function(t,i,r,a,o,l,s){var u;if(void 0!==r){var d=(o.get(t)||new Map).get(i)||[],c=d.map(function(e){return e.text}).join("\n"),v=(null===(u=d[(null==d?void 0:d.length)-1])||void 0===u?void 0:u.reasoning)||"",_=Er(r)||"";if(""===r&&d.length>0||a.trim()!==c.trim()||_!==v){var p=""===r?{updatedItems:[],newIds:[]}:function(t,i,r){if(!t.trim())return{updatedItems:n([],i,!0),newIds:[]};var a=t.match(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g)||[],o=t.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,""),l=[],s=o.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,function(e){return l.push(e),"__CONFLICT_BLOCK_".concat((null==l?void 0:l.length)-1,"__")}).split(/\s*(?:\r?\n|\\+n)\s*/).map(function(e){return e.trim().replace(/^-\s*/,"")}).filter(Boolean),u=new Map(i.map(function(e){return[e.text,e]})),d=[],c=[],v=Array.isArray(null==r?void 0:r.wta)&&t.includes("wta")?r.wta:Array.isArray(null==r?void 0:r.wnta)?r.wnta:[];return s.forEach(function(n,t){var i=n;i.includes("__CONFLICT_BLOCK_")&&(i=i.replace(/__CONFLICT_BLOCK_(\d+)__/g,function(e,n){return l[parseInt(n)]}));var r=a[t]||"",o=i.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,"").trim(),s=null==v?void 0:v.find(function(e){return e.value===o}),_=u.get(i);if(_)c.push(e(e({},_),{reasoning:r||_.reasoning,conflict:s||_.conflict}));else{var p="new-".concat(Date.now(),"-").concat(t);d.push(p),c.push({id:p,text:i,reasoning:r,conflict:s})}}),{updatedItems:c,newIds:d}}(r,d,s),f=p.updatedItems,g=p.newIds;l(function(e){var n=new Map(e),r=new Map(n.get(t)||new Map);return r.set(i,f),n.set(t,r),n}),(null==g?void 0:g.length)>0&&(ti(function(e){return new Set(n(n([],Array.from(e),!0),g,!0))}),setTimeout(function(){ti(function(e){var n=new Set(e);return g.forEach(function(e){return n.delete(e)}),n})},1500))}}},Rr=function(e){return(Array.isArray(e)?e:e?[e]:[]).map(function(e){return String(e).replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/,"").trim().replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})})};d(function(){Vt&&!je.current&&"save this learning"!==Vt.toLowerCase()&&(Ee(!1),Ne(""),Ai.current=null!=Rt?Rt:-1)},[Vt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Fn.current=di,Array.isArray(yt)&&yt.length>0){var c=_i||"local-".concat(Date.now()),v=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],_={},p=bi.current||[];yt.forEach(function(t,i){var r,a;if(t){t.is_readOnly||(tn.current=i);var o=i;if((null==t?void 0:t.variant_id)&&re)-1!==(l=re.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if(tr&&re&&1===yt.length){var l;-1!==(l=re.findIndex(function(e){return e.variantId===tr}))&&(o=l)}var s=null!==(r=p[o])&&void 0!==r?r:p[i],u=null!==(a=t.scope)&&void 0!==a?a:null==s?void 0:s.scope,d=Rr(u).map(function(e){return e.toLowerCase().replace(/ /g,"_")}),c=d.length>0?d:hn.current.length>0?hn.current:["tier_1"];c.length>0&&(hn.current=c),console.log("prevTierRef.current",hn.current,"targetTiers",c);var f=Or(t.title);f&&f!==Or(null==s?void 0:s.title)&&!t.is_readOnly&&function(e,n,t,i,r,a){var o=Or(i);o&&o!==r&&(Ir(e,n,t),a(o))}("global",0,"ruleTitle",t.title,rt,at),c.forEach(function(r){var a,l,s,u,d,c=null!==(a=p[o])&&void 0!==a?a:p[i],f=!c,g=void 0!==t.rule_description&&null!==t.rule_description,m=Or(t.rule_description),w=(null===(l=dt.get(r))||void 0===l?void 0:l.get(o))||"",y=Or(w);g&&(m!==y||""===m&&""!==w)&&(ct(function(e){var n=new Map(e),i=new Map(n.get(r)||new Map);return i.set(o,t.rule_description),n.set(r,i),n}),Ir(r,o,"ruleDescription"));var h=!1===(null==Ft?void 0:Ft.is_valid),b=Or(t.wta),T=Or(null==c?void 0:c.wta),A=(null===(s=_t.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&A.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==T||""===b&&A.length>0||0===A.length&&""!==b)&&(Lr(r,o,t.wta,b,_t,pt,null==Ft?void 0:Ft.conflict_view),Ir(r,o,"wta"));var I=Or(t.wnta),M=Or(null==c?void 0:c.wnta),S=(null===(u=gt.get(r))||void 0===u?void 0:u.get(o))||[];if(!(h&&""===I&&S.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(I!==M||""===I&&S.length>0||0===S.length&&""!==I)&&(Lr(r,o,t.wnta,I,gt,mt,null==Ft?void 0:Ft.conflict_view),Ir(r,o,"wnta")),t.scheduling_config||f||t.variant_type||t.variantType){var k=t.scheduling_config||{order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1}},N=null==c?void 0:c.scheduling_config,C=null===(d=zn.get(r))||void 0===d?void 0:d.get(o),x=t.variant_type||t.variantType,E=x?J(x):void 0,O=JSON.stringify(k)!==JSON.stringify(N),L=void 0!==E&&E!==(null==C?void 0:C.is_default_enabled),R=function(n,t){if(!n)return t;if(!t)return n;var i=e({},n);for(var r in t)t[r]&&"object"==typeof t[r]&&!Array.isArray(t[r])?i[r]=e(e({},i[r]||{}),t[r]):i[r]=t[r];return i};if(zt(function(e){return R(e,k)}),O||L){zt(function(e){return R(e,k)});var D=function(e,n,t,i){var r,a,o,l,s=[],u=(i.get(e)||new Map).get(n)||{order_rules:{enabled:!1,global_min_separation_seconds:0},advertiser_rules:{enabled:!1,global_min_separation_seconds:0},inventory_rules:{respect_inventory_code:!1},break_code_rules:{respect_break_code:!1}};return Math.floor(((null===(r=t.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)||0)/60)!==u.order_rules.global_min_separation_seconds&&s.push("config_order_rules"),Math.floor(((null===(a=t.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)!==u.advertiser_rules.global_min_separation_seconds&&s.push("config_advertiser_rules"),!!(null===(o=t.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)!==u.inventory_rules.respect_inventory_code&&s.push("config_inventory_rules"),!!(null===(l=t.break_code_rules)||void 0===l?void 0:l.respect_break_code)!==u.break_code_rules.respect_break_code&&s.push("config_break_code_rules"),!!t.is_default_enabled!=!!u.is_default_enabled&&s.push("config_is_default_enabled"),s}(r,o,k,zn);D.forEach(function(e){return Ir(r,o,e)}),et(function(e){return new Set(e).add("config")}),Zn(function(n){var t,i,a,l,s,u,d=new Map(n),c=new Map(d.get(r)||new Map),v=c.get(o)||Kn;return c.set(o,e(e(e(e(e(e({},v),k.order_rules&&{order_rules:{enabled:!!(null===(t=k.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=k.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)}}),k.advertiser_rules&&{advertiser_rules:{enabled:!!(null===(a=k.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(l=k.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)||0)/60)}}),k.inventory_rules&&{inventory_rules:{respect_inventory_code:!!(null===(s=k.inventory_rules)||void 0===s?void 0:s.respect_inventory_code)}}),k.break_code_rules&&{break_code_rules:{respect_break_code:!!(null===(u=k.break_code_rules)||void 0===u?void 0:u.respect_break_code)}}),void 0!==E&&{is_default_enabled:E})),d.set(r,c),d}),st(function(e){var n=new Map(e),t=new Map(n.get(r)||new Map),i=t.get(o)||new Set;return k.order_rules&&i.add("order_rules"),k.advertiser_rules&&i.add("advertiser_rules"),k.inventory_rules&&i.add("inventory_rules"),k.break_code_rules&&i.add("break_code_rules"),void 0!==E&&i.add("is_default_enabled"),t.set(o,i),n.set(r,t),n})}}var j={ruleTitle:t.title,ruleDescription:t.rule_description,whenToApply:t.wta,whenNotToApply:t.wnta,scopeData:t.scope,configData:t.action};t.is_readOnly||v.forEach(function(e){var n=Er(j[e]),t="ruleTitle"===e||"scopeData"===e?e:"".concat(e,"_").concat(r);n&&(n!==Gn.current[t]&&(Gn.current[t]=n,Un.current[t]=!0,_[t]={reasoning:n,associatedCitations:[],tier:r,variantIndex:o}))}),t.conflictingConditions&&(Li(function(n){var i=e({},n);return t.conflictingConditions.forEach(function(e){e.condition_wta&&(i["whenToApply-".concat(r,"-").concat(o)]=e.reason),e.condition_wnta&&(i["whenNotToApply-".concat(r,"-").concat(o)]=e.reason)}),i}),et(function(e){return new Set(n(n([],Array.from(e),!0),["conditions"],!1))}))})}});var f=-1,g=!(!te&&!re),m="edit"===Xi||"edit_current_rule"===Xi,w=function(e,n){return(null==e?void 0:e.variant_id)&&e.variant_id===n||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===n||(null==e?void 0:e.id)&&e.id===n},y=function(e,n){if(!n)return-1;var t=e.find(function(e){return w(e,n)});if(!t)return-1;var i=String((null==t?void 0:t.tier_id)||"");if(!i)return e.findIndex(function(e){return w(e,n)});var r=e.filter(function(e){return String((null==e?void 0:e.tier_id)||"")===i}).findIndex(function(e){return w(e,n)});return-1!==r?r:e.findIndex(function(e){return w(e,n)})};if(g)if(Ti.current&&Nt)-1!==(f=yt.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===Ti.current||(null==e?void 0:e.variant_id)&&e.variant_id===Ti.current||(null==e?void 0:e.id)&&e.id===Ti.current}))&&(Ti.current=null);else if(tr||ar){var h;(h=tr||ar)&&(f=y(yt,h))}else if(le&&Array.isArray(yt)&&yt.length>0){for(b=yt.length-1;b>=0;b--)if(yt[b]&&!(null===(i=yt[b])||void 0===i?void 0:i.is_readOnly)){f=b;break}}else null==ae||bi.current&&0!==bi.current.length||(f=ae);else if((h=tr||ar||Ti.current)&&m&&(f=y(yt,h)),!m&&-1===f&&Array.isArray(yt)&&yt.length>0){for(var b=yt.length-1;b>=0;b--)if(yt[b]&&!(null===(t=yt[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=yt.length-1)}-1!==f&&Rt!==f&&(Ai.current===f||Ke.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),Dt(f),Ai.current=f));var T=yt[0];if(T){if(T.scope&&JSON.stringify(T.scope)!==JSON.stringify(null===(r=p[0])||void 0===r?void 0:r.scope)&&"copy"!==T.action&&(l=T.scope,s=null===(a=p[0])||void 0===a?void 0:a.scope,u=Rr(l),d=s?Rr(s):[],me(function(n){return e(e({},n),{tiers:u})}),u.forEach(function(e){var n=e.trim();d.includes(e)||Ir("global",0,"scope_".concat(n))})),T.scope_rule_set&&T.scope_rule_set!==(null===(o=p[0])||void 0===o?void 0:o.scope_rule_set)){var A=T.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(A)&&(me(function(n){return e(e({},n),{station:A})}),Ir("global",0,"scope_station"))}T.wtl&&tt(T.wtl)}bi.current=yt.map(function(e){return e?(n=e,"function"==typeof(t=null===globalThis||void 0===globalThis?void 0:globalThis.structuredClone)?t(n):JSON.parse(JSON.stringify(n))):e;var n,t}),Object.keys(_).length>0&&(vr({type:"SAVE_CITATIONS",requestId:c,reasoningMap:_,rawCitations:di}),function(e){var n=e.requestId,t=e.keys,i=e.newReasoningMap,r=e.getLatestReasoning,a=e.currentCitations;console.group("%c Citation Audit: ".concat(n," "),"background: #5928ed; color: #fff; font-weight: bold;");var o={};t.forEach(function(e){var n=r(e),t=!!i[e],l=t?a:(null==n?void 0:n.associatedCitations)||[];o[e]={Status:t?"NEW ✅":n?"FALLBACK 🔄":"EMPTY ❌",Source:t?"Current Msg":n?"History":"N/A","Reasoning Preview":t?i[e].reasoning:(null==n?void 0:n.reasoning)||"None","Full Citations":l}}),console.table(o),console.groupEnd()}({requestId:c,keys:Object.keys(_),newReasoningMap:_,getLatestReasoning:_r,currentCitations:di}),si(function(n){var t=e({},n),i=!1;return Object.keys(_).forEach(function(e){var n=_[e];n.reasoning&&t[e]!==n.reasoning&&(t[e]=n.reasoning,i=!0),n.associatedCitations}),i?t:n}))}},[yt,di,_i]),d(function(){var t=Object.keys(Un.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],di,!0)}),Un.current={},mi(function(n){return e(e({},n),i)})}},[di]);var Dr=function(e){return e.map(function(e){var n;return null===(n=e.match(/\d+/))||void 0===n||n[0],e.replace(/\s+/g,"-"),{name:"Custom",parentScopeId:null,scopeRowId:(null==ne?void 0:ne.ruleSetId)||"",value:{scopeName:(null==ne?void 0:ne.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==Hn?void 0:Hn.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==ne?void 0:ne.ruleSetDesc)||""}}})},jr=function(e){var n={};return Object.entries(e).forEach(function(e){var t,i=e[0],r=e[1];if("custom_sep_time_for_entities"===i&&r)n.custom_sep_time_for_entities=r;else if("max_priority_override"===i&&r&&void 0!==r.override_priority_code)n.override_priority_code=r.override_priority_code;else if("advertiser_pair_break_constraint"===i&&r)n.advertiser_pair_break_constraint=r.advertiser_pair_list;else if(r&&"object"==typeof r&&(null===(t=Object.keys(r))||void 0===t?void 0:t.length)>0){var a=i.replace(/_rules$/,""),o=["global_min_separation_seconds","respect_inventory_code","respect_break_code","exemption_advertiser_list","exemption_break_code_list","exemption_priority_code_list","priority_code_list","exemption_product_code_list","condition_advertiser_list","condition_break_code_list","condition_priority_code_list","condition_product_code_list"];Object.entries(r).forEach(function(e){var t=e[0],r=e[1];if(o.includes(t)&&("product_rules"!==i||"global_min_separation_seconds"!==t)){var l="respect_inventory_code"===t||"respect_break_code"===t?t:"".concat(a,"_").concat(t);n[l]=r}})}else if(void 0!==r&&"object"!=typeof r){if("station_guid"===i||"is_default_enabled"===i)return;n[i]=r}}),{config_structure:{scheduling_config:{advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",advertiser_exemption_priority_code_list:"array",advertiser_exemption_product_code_list:"array",advertiser_global_min_separation_seconds:"int",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",break_code_exemption_priority_code_list:"array",break_code_exemption_product_code_list:"array",custom_sep_time_for_entities:"object",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",inventory_exemption_priority_code_list:"array",inventory_exemption_product_code_list:"array",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",order_exemption_product_code_list:"array",order_global_min_separation_seconds:"int",override_priority_code:"str",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",product_exemption_product_code_list:"array",max_priority_override_priority_code_list:"array",max_priority_override_exemption_advertiser_list:"array",max_priority_override_exemption_break_code_list:"array",max_priority_override_exemption_priority_code_list:"array",max_priority_override_exemption_product_code_list:"array",first_in_break_exemption_advertiser_list:"array",first_in_break_exemption_break_code_list:"array",first_in_break_exemption_priority_code_list:"array",first_in_break_exemption_product_code_list:"array",first_in_break_condition_advertiser_list:"array",first_in_break_condition_break_code_list:"array",first_in_break_condition_priority_code_list:"array",first_in_break_condition_product_code_list:"array",advertiser_pair_break_constraint:"array",respect_break_code:"bool",respect_inventory_code:"bool"}},config_data:{scheduling_config:n}}},Vr=function(n,t,i,r){void 0===r&&(r=0);var a=e({},t||{});return n.forEach(function(n,o){var l=n.get(r);l&&l.forEach(function(n){var l,s=t[n]||{},u=i.get(o),d=null==u?void 0:u.get(r),c=null==d?void 0:d[n];if("order_rules"===n||"advertiser_rules"===n){var v=null!==(l=null==c?void 0:c.enabled)&&void 0!==l&&l?60*((null==c?void 0:c.global_min_separation_seconds)||0):0;a[n]=e(e({},s),{global_min_separation_seconds:v})}else a[n]="inventory_rules"===n?e(e({},s),{respect_inventory_code:null==c?void 0:c.respect_inventory_code}):"break_code_rules"===n?e(e({},s),{respect_break_code:null==c?void 0:c.respect_break_code}):"is_default_enabled"===n?null!=c&&c:s})}),a},Pr=function(e,n,t){void 0===t&&(t="variantType");var i=null==e?void 0:e[n];if(!i)return{label:Nr(e),isDefault:!1};var r=i[t]||"",a=J(r);return{label:"variant ".concat(n+1),isDefault:a}},Gr=function(e,n){var t=J(e);return{label:"variant ".concat(n+1),isDefault:t}},Fr=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=zn.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":J(t)?"Default":"Variant"},qr=function(n,o){return void 0===o&&(o=!1),t(void 0,void 0,void 0,function(){var t,l,s,u,d,c,v,p,g,w,h,b,T,A,S,k,N;return i(this,function(i){switch(i.label){case 0:t=Dr(ge.tiers),l=I.getState().backwardCompatibility,s=tn.current,u=Vr(lt,Qt,zn,s),i.label=1;case 1:return i.trys.push([1,3,,4]),he(q),Ne(""),d=jr(u),c=m(),v=[],p=[],g=(yt||[])[s]||{},console.log("originalItem check :",g,s),ge.tiers.forEach(function(i){var r,a,o,u,_,f,w,h,b,T,A,I,M,S,k,N,C,x,E=i.toLowerCase().replace(/ /g,"_");p.push(E);var O=(null===(r=dt.get(E))||void 0===r?void 0:r.get(s))||"",L=(null===(a=_t.get(E))||void 0===a?void 0:a.get(s))||[],R=(null===(o=gt.get(E))||void 0===o?void 0:o.get(s))||[];if(!1===l){var D=[e(e({},d&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:c,variant:Or(O),conditions_whentoapply:L.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:R.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(f=null===(_=null===(u=zn.get(E))||void 0===u?void 0:u.get(s))||void 0===_?void 0:_.is_default_enabled)||void 0===f||f,tier_id:(null===(w=Ve.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===E||e.tier_name.toLowerCase()===E.replace(/_/g,"")}))||void 0===w?void 0:w.tier_id)||"",topic_id:null,scope_id:(null==ne?void 0:ne.ruleSetId)||"",question_title:rt,variantType:Fr(E,s,g.variant_type||g.variantType),instantLearningType:Hn.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:pe,modeId:"019e1e39-2030-7775-8312-0ad525700588"})];v.push(y(D,Hn.ASSISTANT_NAME))}else{D={status:"approved",metadata:e(e({userName:null!==(h=null==dr?void 0:dr.firstname)&&void 0!==h?h:"",userEmailId:null!==(b=null==dr?void 0:dr.email)&&void 0!==b?b:"",llm:j.MODEL,isVariantFlow:!0},d&&{config:e({master_name:j.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:c,variant:Or(O),conditions_whentoapply:L.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:R.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:t[0]||{name:j.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ne?void 0:ne.ruleSetId)||"",value:{scopeName:(null==ne?void 0:ne.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:j.CUSTOM_SCOPE_GROUP_NAME,description:(null==ne?void 0:ne.ruleSetDesc)||""}},overriden:!1,isDefault:null===(I=null===(A=null===(T=zn.get(E))||void 0===T?void 0:T.get(s))||void 0===A?void 0:A.is_default_enabled)||void 0===I||I,tier:{name:i.split(" ").join("").toLowerCase(),tierGroupName:j.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(M=Ve.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===E||e.tier_name.toLowerCase()===E.replace(/_/g,"")}))||void 0===M?void 0:M.tier_id)||""},topic:{id:null,value:"".concat(ge.station||ee,"RuleSet"),description:null},categories:[{id:null,value:j.CATEGORY,description:j.CATEGORY}],originalQuestion:rt,questionId:n.get(E)||null,variantType:Fr(E,s,g.variant_type||g.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(S=null==dr?void 0:dr.email)&&void 0!==S?S:"",instantLearningType:j.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(k=null==g?void 0:g.is_user_accepted_risk)&&void 0!==k?k:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0}),appsecData:{application:null!==(N=null==Yn?void 0:Yn.applicationId)&&void 0!==N?N:"",scopeLevelModuleId:(null==Yn?void 0:Yn.moduleId)||"",applicationLevelModuleId:null!==(C=null==Yn?void 0:Yn.applicationModuleId)&&void 0!==C?C:"",applicationLevelResourceId:null!==(x=null==Yn?void 0:Yn.applicationResourceId)&&void 0!==x?x:""}};v.push(y(D,Hn.ASSISTANT_NAME))}}),[4,Promise.all(v)];case 2:return w=i.sent(),De(!1),console.log("✅ All feedback published:",w),he(G),Ae(!0),h=new Map,w.forEach(function(e,n){var t,i,r=p[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=h.get(r)||[];o.push({id:a,action:"new"}),h.set(r,o)}}),I.getState().setCreatedVariantInfo(Array.from(h.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(S=Ii.current)||void 0===S||S.show({severity:"success",sticky:!1,life:6e3,className:M.toastSuccess,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(f,{className:M.iconSuccess}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),Oe.current=setTimeout(function(){Pi||o?(console.log("Closing modal after save success",{isCloseModal:Pi,forceClose:o}),la()):kr(!0)},3e3),[3,4];case 3:return b=i.sent(),console.error("❌ Error publishing feedback:",b),De(!1),he(F),Ee(!0),T=(null===(k=null==b?void 0:b.response)||void 0===k?void 0:k.data)||{},console.log("errorData: ",T),(A="Variant already exists"===(null==T?void 0:T.message))||409===(null==b?void 0:b.status)?Ne('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):Ne(((null==T?void 0:T.message)||(null==T?void 0:T.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(N=Ii.current)||void 0===N||N.show({severity:"error",sticky:!1,className:M.toastError,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(_,{className:M.iconError}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageError)},{children:A||409===(null==b?void 0:b.status)?"Similar rule already exists. Please update and try again.":(null==T?void 0:T.message)||(null==T?void 0:T.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Ur=function(){return t(void 0,void 0,void 0,function(){var t,o,l,s,u,d,c,v,p,g,w,b,T,A,S,k,N,C,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:t=I.getState().tiers,o=Vr(lt,Qt,zn),l=jr(o),s=tn.current,u=(yt||[])[s]||{},d=(null==Ft?void 0:Ft.variant_type)||u.variant_type||"",i.label=1;case 1:for(i.trys.push([1,3,,4]),he(q),Ne(""),v=(c=re||[]).length>0?null===(O=c.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===O?void 0:O.link_id:null,p=(null===(L=ge.tiers[0])||void 0===L?void 0:L.toLowerCase().replace(/ /g,"_"))||"tier_1",g=(null===(R=dt.get(p))||void 0===R?void 0:R.size)||c.length,w=n([],c,!0),b=c.length;b<g;b++)w.push({isNewVariant:!0,variantId:m()});return T=[],A=[],S=Dr(ge.tiers),ge.tiers.forEach(function(n){var i=n.toLowerCase().replace(/ /g,"_"),r=t.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=dt.get(i),o=_t.get(i),s=gt.get(i);w.forEach(function(t,c){var _,p,f,g,w,b,I,M,k,N,C,x,E,O,L,R,D,j,V,P,G,F,q,H,B,W,Y,K,Q=(null==a?void 0:a.get(c))||t.description||"",z=(null==o?void 0:o.get(c))||[],Z=(null==s?void 0:s.get(c))||[];if(t.isNewVariant){A.push({tierKey:i,payloadType:"new"});var $=Vr(lt,Qt,zn,c),X=jr($);console.log("variant in save edit add part :",t,u);var ee={status:"approved",metadata:e(e({userName:null!==(_=null==dr?void 0:dr.firstname)&&void 0!==_?_:"",userEmailId:null!==(p=null==dr?void 0:dr.email)&&void 0!==p?p:"",llm:Hn.MODEL,isVariantFlow:!0},X&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},X)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:v||m(),variant:Or(Q),conditions_whentoapply:z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:Z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:S[0]||{name:Hn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ne?void 0:ne.ruleSetId)||"",value:{scopeName:(null==ne?void 0:ne.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Hn.CUSTOM_SCOPE_GROUP_NAME,description:(null==ne?void 0:ne.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=zn.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:J(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:Hn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(ge.station,"RuleSet"),description:null},categories:[{id:null,value:Hn.CATEGORY,description:Hn.CATEGORY}],originalQuestion:rt,questionId:null==te?void 0:te.ruleId,variantType:Fr(i,c,u.variant_type||""),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==dr?void 0:dr.email)&&void 0!==b?b:"",instantLearningType:Hn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(M=null===(I=(yt||[])[c])||void 0===I?void 0:I.is_user_accepted_risk)&&void 0!==M?M:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",ee),T.push(y(ee,Hn.ASSISTANT_NAME))}else{A.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var ie=t.variantId===tr,re=Fr(i,c,ie?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",re,ie,t,tr);var ae={variantId:t.variantId,ruleDesc:(null==ne?void 0:ne.ruleSetDesc)||"",whenToApply:z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:Z.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(C=null===(N=null===(k=zn.get(i))||void 0===k?void 0:k.get(c))||void 0===N?void 0:N.is_default_enabled)&&void 0!==C?C:J(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||n,tier_priority:null!==(x=null==r?void 0:r.tier_priority)&&void 0!==x?x:null},scope_id:(null==ne?void 0:ne.ruleSetId)||"",description:Or(Q)||"",topic:"".concat(ge.station,"RuleSet"),configuration:(null==l?void 0:l.config_data)||{},tierLinkId:null!=v?v:null,variantType:re,is_user_accepted_risk:!!(null!==(O=null===(E=(yt||[])[c])||void 0===E?void 0:E.is_user_accepted_risk)&&void 0!==O?O:null==t?void 0:t.is_user_accepted_risk),is_enabled:t.is_enabled},oe=(Tt.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===t.variantId}),le=!0;if(oe){var se=function(e){var n=(e||"").trim();return(n=U(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ue=se(rt)===se(oe.title),de=se(Q)===se(oe.rule_description),ce=se(ae.whenToApply)===se(oe.wta),ve=se(ae.whenNotToApply)===se(oe.wnta),_e=!!ae.isDefault===J(oe.variant_type),pe=oe.scheduling_config||{},fe=null!==(D=null!==(L=pe.order_global_min_separation_seconds)&&void 0!==L?L:null===(R=pe.order_rules)||void 0===R?void 0:R.global_min_separation_seconds)&&void 0!==D?D:0,me=null!==(P=null!==(j=pe.advertiser_global_min_separation_seconds)&&void 0!==j?j:null===(V=pe.advertiser_rules)||void 0===V?void 0:V.global_min_separation_seconds)&&void 0!==P?P:0,we=null!==(q=null!==(F=null===(G=pe.inventory_rules)||void 0===G?void 0:G.respect_inventory_code)&&void 0!==F?F:pe.respect_inventory_code)&&void 0!==q&&q,ye=null!==(W=null!==(B=null===(H=pe.break_code_rules)||void 0===H?void 0:H.respect_break_code)&&void 0!==B?B:pe.respect_break_code)&&void 0!==W&&W,he=(null===(Y=zn.get(i))||void 0===Y?void 0:Y.get(c))||Kn,be=he.order_rules.enabled===fe>0&&he.order_rules.global_min_separation_seconds===Math.floor(fe/60)&&he.advertiser_rules.enabled===me>0&&he.advertiser_rules.global_min_separation_seconds===Math.floor(me/60)&&he.inventory_rules.respect_inventory_code===we&&he.break_code_rules.respect_break_code===ye;ue&&de&&ce&&ve&&_e&&be&&(le=!1)}le?(console.log("payloadv (update existing variant)",ae),T.push(h(ae,null!==(K=null==dr?void 0:dr.email)&&void 0!==K?K:""))):(console.log("[saveEditedVariant] No changes for variant ".concat(t.variantId,", skipping API call")),T.push(Promise.resolve({data:{id:t.variantId},skipped:!0})))}})}),[4,Promise.all(T)];case 2:return k=i.sent(),console.log("✅ All variants updated:",k),he(G),Ae(!0),De(!1),N=new Map,k.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=A[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id);a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data);var o="existing"===r.payloadType?r.existingId:a;if(o&&"string"==typeof o){var l=N.get(r.tierKey)||[];l.push({id:o,action:r.payloadType}),N.set(r.tierKey,l)}}}),I.getState().setCreatedVariantInfo(Array.from(N.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=Ii.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:M.toastSuccess,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(f,{className:M.iconSuccess}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Oe.current=setTimeout(function(){la()},3e3),[3,4];case 3:return C=i.sent(),console.error("❌ Error updating variant:",C),he(F),Ee(!0),De(!1),x=(null===(j=null==C?void 0:C.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",x),(E="Variant already exists"===(null==x?void 0:x.message))||409===(null==C?void 0:C.status)?Ne('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):Ne(((null==x?void 0:x.message)||(null==x?void 0:x.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=Ii.current)||void 0===V||V.show({severity:"error",sticky:!1,className:M.toastError,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(_,{className:M.iconError}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageError)},{children:E||409===(null==C?void 0:C.status)?"Similar rule already exists. Please update and try again.":(null==x?void 0:x.message)||(null==x?void 0:x.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Jr=function(){return t(void 0,void 0,void 0,function(){var n,t,o,l,s,u,d,c,v,p,g,w,b,T,A,S,k,N,C,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:n=I.getState().tiers,t=Vr(lt,Qt,zn),o=jr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),he(q),Ne(""),0===(l=Array.isArray(yt)?yt:[]).length?(console.warn("No variants found to save."),he(F),[2]):(s=l.filter(function(e){return e.is_new_variant}),u=l.filter(function(e){return!e.is_new_variant&&(null==e?void 0:e.variant_id)}),console.log("[saveLoadAndEditVariant] New: ".concat(s.length,", Existing: ").concat(u.length)),d=u.length>0?null===(R=u.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===R?void 0:R.link_id:null,c=[],v=[],p=[],g=[],w=Dr(ge.tiers),ge.tiers.forEach(function(t){var i=t.toLowerCase().replace(/ /g,"_"),r=n.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=dt.get(i),s=_t.get(i),u=gt.get(i);l.forEach(function(n,l){var _,f,y,b,T,A,I,M,S,k,N,C,x,E,O,L,R,D,j,V,P,G,F,q,H,B,W,Y=(null==a?void 0:a.get(l))||n.rule_description||n.description||"",K=(null==s?void 0:s.get(l))||[],Q=(null==u?void 0:u.get(l))||[];if(n.is_new_variant){var z=Vr(lt,Qt,zn,l),Z=jr(z),$=Fr(i,l,n.variant_type||n.variantType||""),X={status:"approved",metadata:e(e({userName:null!==(_=null==dr?void 0:dr.firstname)&&void 0!==_?_:"",userEmailId:null!==(f=null==dr?void 0:dr.email)&&void 0!==f?f:"",llm:Hn.MODEL,isVariantFlow:!0},Z&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},Z)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Or(Y),conditions_whentoapply:K.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:Q.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:w[0]||{name:Hn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ne?void 0:ne.ruleSetId)||"",value:{scopeName:(null==ne?void 0:ne.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Hn.CUSTOM_SCOPE_GROUP_NAME,description:(null==ne?void 0:ne.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(T=null===(b=null===(y=zn.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==T?T:J(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:Hn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(t.split(" ")[1]||"1"),tier_id:(null==r?void 0:r.tier_id)||""},topic:{id:null,value:"".concat(ge.station||ee,"RuleSet"),description:null},categories:[{id:null,value:Hn.CATEGORY,description:Hn.CATEGORY}],originalQuestion:rt,questionId:jn.current||null,variantType:$,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(A=null==dr?void 0:dr.email)&&void 0!==A?A:"",instantLearningType:Hn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(I=null==n?void 0:n.is_user_accepted_risk)&&void 0!==I?I:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",X),v.push({payload:X,tierKey:i}),g.push({tierKey:i})}else if(null==n?void 0:n.variant_id){p.push({tierKey:i,existingId:n.variant_id});var te=(null==n?void 0:n.variant_id)&&n.variant_id===sr?(null==Ft?void 0:Ft.variant_type)||n.variant_type||n.variantType||"":n.variant_type||n.variantType||"",ie=($=Fr(i,l,te),{variantId:n.variant_id,ruleDesc:(null==ne?void 0:ne.ruleSetDesc)||"",whenToApply:K.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:Q.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(k=null===(S=null===(M=zn.get(i))||void 0===M?void 0:M.get(l))||void 0===S?void 0:S.is_default_enabled)&&void 0!==k?k:J(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||t,tier_priority:null!==(N=null==r?void 0:r.tier_priority)&&void 0!==N?N:null},scope_id:(null==ne?void 0:ne.ruleSetId)||"",description:Or(Y)||"",topic:"".concat(ge.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:$,is_user_accepted_risk:!!(null!==(C=null==n?void 0:n.is_user_accepted_risk)&&void 0!==C?C:null===(x=(yt||[])[l])||void 0===x?void 0:x.is_user_accepted_risk),is_enabled:n.is_enabled}),re=(Tt.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===(null==n?void 0:n.variant_id)}),ae=!0;if(re){var oe=function(e){var n=(e||"").trim();return(n=U(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},le=oe(rt)===oe(re.title),se=oe(Y)===oe(re.rule_description),ue=oe(ie.whenToApply)===oe(re.wta),de=oe(ie.whenNotToApply)===oe(re.wnta),ce=!!ie.isDefault===J(re.variant_type),ve=re.scheduling_config||{},_e=null!==(L=null!==(E=ve.order_global_min_separation_seconds)&&void 0!==E?E:null===(O=ve.order_rules)||void 0===O?void 0:O.global_min_separation_seconds)&&void 0!==L?L:0,pe=null!==(j=null!==(R=ve.advertiser_global_min_separation_seconds)&&void 0!==R?R:null===(D=ve.advertiser_rules)||void 0===D?void 0:D.global_min_separation_seconds)&&void 0!==j?j:0,fe=null!==(G=null!==(P=null===(V=ve.inventory_rules)||void 0===V?void 0:V.respect_inventory_code)&&void 0!==P?P:ve.respect_inventory_code)&&void 0!==G&&G,me=null!==(H=null!==(q=null===(F=ve.break_code_rules)||void 0===F?void 0:F.respect_break_code)&&void 0!==q?q:ve.respect_break_code)&&void 0!==H&&H,we=(null===(B=zn.get(i))||void 0===B?void 0:B.get(l))||Kn,ye=we.order_rules.enabled===_e>0&&we.order_rules.global_min_separation_seconds===Math.floor(_e/60)&&we.advertiser_rules.enabled===pe>0&&we.advertiser_rules.global_min_separation_seconds===Math.floor(pe/60)&&we.inventory_rules.respect_inventory_code===fe&&we.break_code_rules.respect_break_code===me;le&&se&&ue&&de&&ce&&ye&&(ae=!1)}ae?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ie),c.push(h(ie,null!==(W=null==dr?void 0:dr.email)&&void 0!==W?W:""))):(console.log("[saveLoadAndEditVariant] No changes for variant ".concat(n.variant_id,", skipping API call")),c.push(Promise.resolve({data:{id:n.variant_id},skipped:!0})))}})}),[4,Promise.all(c)]);case 2:b=i.sent(),console.log("✅ All existing variants updated:",b),T=[],A=0,S=v,i.label=3;case 3:if(!(A<S.length))return[3,8];k=S[A],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(k.payload,Hn.ASSISTANT_NAME)];case 5:return N=i.sent(),T.push(N),[3,7];case 6:throw C=i.sent(),console.error("❌ Error publishing new variant:",C),C;case 7:return A++,[3,3];case 8:return console.log("✅ All new variants published:",T),x=new Map,b.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=p[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data);var o=r.existingId||a;if(o&&"string"==typeof o){var l=x.get(r.tierKey)||[];l.push({id:o,action:"existing"}),x.set(r.tierKey,l)}}}),T.forEach(function(e,n){var t,i,r=g[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=x.get(r.tierKey)||[];o.push({id:a,action:"new"}),x.set(r.tierKey,o)}}),I.getState().setCreatedVariantInfo(Array.from(x.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),he(G),Ae(!0),De(!1),Ke.current=!1,null===(D=Ii.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:M.toastSuccess,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(f,{className:M.iconSuccess}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Oe.current=setTimeout(function(){la()},3e3),[3,10];case 9:return E=i.sent(),console.error("❌ Error updating variant:",E),he(F),Ee(!0),De(!1),O=(null===(j=null==E?void 0:E.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",O),(L="Variant already exists"===(null==O?void 0:O.message))||409===(null==E?void 0:E.status)?Ne('Looks like a similar rule already exists with the same conditions. You can update the description or conditions to make it unique, or discard this learning. <br/> How would you like to proceed?\n <br/><button class="clickable-button" data-value="Discard learning">Discard learning</button>\n <br/><button class="clickable-button" data-value="Continue editing learning">Continue editing learning</button>\n <br/><button class="clickable-button" id="typeYourAnswer">Or, type your response</button>'):Ne(((null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=Ii.current)||void 0===V||V.show({severity:"error",sticky:!1,className:M.toastError,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(_,{className:M.iconError}),a("span",e({className:"".concat(M.toastTitle," ").concat(M.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(M.toastMessage," ").concat(M.toastMessageError)},{children:L||409===(null==E?void 0:E.status)?"Similar rule already exists. Please update and try again.":(null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,10];case 10:return[2]}})})},Hr=function(e){return"string"!=typeof e?e:e.replace(/<conflicting_text>[\s\S]*?<\/conflicting_text>/g,"").replace(/<decision_strength>[\s\S]*?<\/decision_strength>/g,"").replace(/<conflicting_reasoning>[\s\S]*?<\/conflicting_reasoning>/g,"").replace(/<conflicting_gap>[\s\S]*?<\/conflicting_gap>/g,"").replace(/<\/?conflicting>/g,"").trim()};d(function(){qi&&!yi&&(console.log("isSaveRule received from agent — calling publish APIs directly."),Ui(!1),te||re?Ur():!0===Ke.current?Jr():t(void 0,void 0,void 0,function(){var e,n,t,r,a,o,l,s;return i(this,function(u){switch(u.label){case 0:u.trys.push([0,5,,6]),he(q),e=new Map,n=function(n){var t,r,a,o,l,u;return i(this,function(i){switch(i.label){case 0:if(t=n.toLowerCase().replace(/ /g,"_"),r=Ve.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return e.set(t,null),[2,"continue"];o={question:rt,orgName:Hn.ORGANIZATION_NAME,scope_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),e.set(t,(null===(s=null==l?void 0:l.data)||void 0===s?void 0:s.id)||null),console.log("✅ Question saved for ".concat(n,":"),l),[3,4];case 3:return u=i.sent(),console.error("❌ Error saving question for ".concat(n,":"),u),e.set(t,null),[3,4];case 4:return[2]}})},t=0,r=ge.tiers,u.label=1;case 1:return t<r.length?(a=r[t],[5,n(a)]):[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return qr(e),[3,6];case 5:return o=u.sent(),l=new Map,ge.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),qr(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[qi,yi]);var Br=(null===(W=(null===(B=null==ge?void 0:ge.tiers)||void 0===B?void 0:B[0])||ie||"Tier 1")||void 0===W?void 0:W.toLowerCase().replace(/ /g,"_"))||"tier_1",Wr=null!==(Y=null!=Rt?Rt:ae)&&void 0!==Y?Y:0,Yr=null!=Rt,Kr=Yr?null==yt?void 0:yt[Wr]:null,Qr=yt&&(null==yt?void 0:yt.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Wt.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&Jt.includes(e.variant_id))})),zr=(null==Kr?void 0:Kr.new_variant_id)&&Wt.includes(Kr.new_variant_id)?Kr.new_variant_id:(null==Qr?void 0:Qr.new_variant_id)&&Wt.includes(Qr.new_variant_id)?Qr.new_variant_id:"",Zr=!(!te&&!re),$r=function(n){var t={},i=ge.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),r=(null==ge?void 0:ge.station)+"RuleSet",a=i.map(function(e){var n=Ve.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return n.forEach(function(n,o){var l,s,u,d,c,v,_=(null==n?void 0:n.variant_id)&&n.variant_id||Jt[o]||"new_variant_".concat(o),p=(null===(l=n.scope)||void 0===l?void 0:l[0])||Br,f=dt.get(p),g=_t.get(p),m=gt.get(p),w=(null==f?void 0:f.get(o))||n.rule_description||"",y=(null==g?void 0:g.get(o))||[],h=y.length>0?y.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wta||"",b=(null==m?void 0:m.get(o))||[],T=b.length>0?b.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wnta||"",A=zn.get(p),I=null==A?void 0:A.get(o),M={};I&&Object.keys(I).length>0?M=e(e({},I),{order_rules:e(e({},I.order_rules),{global_min_separation_seconds:60*((null===(s=I.order_rules)||void 0===s?void 0:s.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},I.advertiser_rules),{global_min_separation_seconds:60*((null===(u=I.advertiser_rules)||void 0===u?void 0:u.global_min_separation_seconds)||0)})}):n.scheduling_config&&(M=n.scheduling_config),t[_]={rule_title:rt,variant_description:w,wta:h,ruleset_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:a,wnta:T,scope:i,scope_rule_set:r,scheduling_config:M,is_user_accepted_risk:!(null===(v=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(yt||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===v||!v)}}),t};An&&console.log("customMetaData.ui_state for addvariant flow",$r(Mt));var Xr=I(function(e){return e.selectedRuleSetId});Be.current={send_metadata_to_orchestrator:!1,default:["scope"],app_mapping_id:pe,save_api_payload:function(){var n;if(!(null===(n=ge.tiers)||void 0===n?void 0:n.length)||!(null==Ve?void 0:Ve.length))return[];var t=I.getState().backwardCompatibility,i=tn.current,r=(yt||[])[i]||{},a=Vr(lt,Qt,zn,i),o=jr(a),l=m(),s=Dr(ge.tiers);return ge.tiers.map(function(n){var a,u,d,c,v,_,p,f,g,w,y,h,b,T,A,I=n.toLowerCase().replace(/ /g,"_"),M=(null===(a=dt.get(I))||void 0===a?void 0:a.get(i))||"",S=(null===(u=_t.get(I))||void 0===u?void 0:u.get(i))||[],k=(null===(d=gt.get(I))||void 0===d?void 0:d.get(i))||[];return!1===t?e(e({},o&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},o)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:l,variant:Or(M),conditions_whentoapply:S.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:k.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(_=null===(v=null===(c=zn.get(I))||void 0===c?void 0:c.get(i))||void 0===v?void 0:v.is_default_enabled)||void 0===_||_,tier_id:(null===(p=Ve.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===I||e.tier_name.toLowerCase()===I.replace(/_/g,""))}))||void 0===p?void 0:p.tier_id)||"",topic_id:null,scope_id:(null==ne?void 0:ne.ruleSetId)||"",question_title:rt,variantType:Fr(I,i,r.variant_type||r.variantType),instantLearningType:Hn.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:pe,modeId:"019e1e39-2030-7775-8312-0ad525700588"}):{status:"approved",metadata:e(e({userName:null!==(f=null==dr?void 0:dr.firstname)&&void 0!==f?f:"",userEmailId:null!==(g=null==dr?void 0:dr.email)&&void 0!==g?g:"",llm:j.MODEL,isVariantFlow:!0},o&&{config:e({master_name:j.CONFIG_MASTER_NAME},o)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:l,variant:Or(M),conditions_whentoapply:S.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:k.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:s[0]||{name:j.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ne?void 0:ne.ruleSetId)||"",value:{scopeName:(null==ne?void 0:ne.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:j.CUSTOM_SCOPE_GROUP_NAME,description:(null==ne?void 0:ne.ruleSetDesc)||""}},overriden:!1,isDefault:null===(h=null===(y=null===(w=zn.get(I))||void 0===w?void 0:w.get(i))||void 0===y?void 0:y.is_default_enabled)||void 0===h||h,tier_id:(null===(b=Ve.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===I||e.tier_name.toLowerCase()===I.replace(/_/g,""))}))||void 0===b?void 0:b.tier_id)||"",topic:{id:null,value:"".concat(ge.station||ee,"RuleSet"),description:null},categories:[{id:null,value:j.CATEGORY,description:j.CATEGORY}],originalQuestion:rt,questionId:null,variantType:Fr(I,i,r.variant_type||r.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(T=null==dr?void 0:dr.email)&&void 0!==T?T:"",instantLearningType:j.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(A=null==r?void 0:r.is_user_accepted_risk)&&void 0!==A?A:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0})}})}(),ui_state:Zr?{variants:function(){var n={},t=zn.get(Br);if(!t)return n;var i=dt.get(Br),r=_t.get(Br),a=gt.get(Br),o=ge.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),l=(null==ge?void 0:ge.station)+"RuleSet",s=o.map(function(e){var n=Ve.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return t.forEach(function(u,d){var c,v,_,p,f,g,m=null===(c=null==re?void 0:re[d])||void 0===c?void 0:c.variantId,w=(yt||[])[d],y=(null==w?void 0:w.new_variant_id)||"",h=m||y||Jt[d]||"variant_".concat(d),b=(null==i?void 0:i.get(d))||"",T=((null==r?void 0:r.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",A=((null==a?void 0:a.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",I=t.get(d),M={};I&&Object.keys(I).length>0&&(M=e(e({},I),{order_rules:e(e({},I.order_rules),{global_min_separation_seconds:60*((null===(v=I.order_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},I.advertiser_rules),{global_min_separation_seconds:60*((null===(_=I.advertiser_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)})})),n[h]={rule_title:rt,variant_description:b,wta:T,ruleset_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:s,wnta:A,scope:o,scope_rule_set:l,scheduling_config:M,is_user_accepted_risk:!(null===(g=null!==(p=null==w?void 0:w.is_user_accepted_risk)&&void 0!==p?p:null===(f=null==re?void 0:re[d])||void 0===f?void 0:f.is_user_accepted_risk)||void 0===g||!g)}}),n}()}:function(){var n,t,i,r,a,o,l=(yt||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:mn?s=-1:An||(s=Wr),{new_current_variant:-1!==s?{rule_title:rt,rule_description:(null===(n=dt.get(Br))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=_t.get(Br))||void 0===t?void 0:t.get(s))||void 0===i?void 0:i.map(function(e){return Hr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",wnta:(null===(a=null===(r=gt.get(Br))||void 0===r?void 0:r.get(s))||void 0===a?void 0:a.map(function(e){return Hr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",scope:ge.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),scope_rule_set:(null==ge?void 0:ge.station)+"RuleSet",scheduling_config:function(){var n,t,i,r=null===(n=zn.get(Br))||void 0===n?void 0:n.get(s);return r&&0!==Object.keys(r).length?e(e({},r),{order_rules:e(e({},r.order_rules),{global_min_separation_seconds:60*((null===(t=r.order_rules)||void 0===t?void 0:t.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},r.advertiser_rules),{global_min_separation_seconds:60*((null===(i=r.advertiser_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)})}):{}}(),is_user_accepted_risk:!!(null===(o=(yt||[])[s])||void 0===o?void 0:o.is_user_accepted_risk)}:{rule_title:"",rule_description:"",wta:"",wnta:"",scope:[],scope_rule_set:"",scheduling_config:{},is_user_accepted_risk:!1},variants:An?$r(Mt):{}}}(),rule_id_in_current_session:Et,new_variant_id:function(){var e;return Yr&&te?(null===(e=null==re?void 0:re[Wr])||void 0===e?void 0:e.variantId)?null:zr:null}(),edit_variant_id:Rn,rule_id:jn.current,backward_compatibility:I.getState().backwardCompatibility,ruleset_id:Xr,current_variants_length:te?Array.isArray(yt)&&yt.length>0?Math.max((null===(K=null==te?void 0:te.variants)||void 0===K?void 0:K.length)||0,yt.length):null===(Q=null==te?void 0:te.variants)||void 0===Q?void 0:Q.length:void 0,tiers:I.getState().tiers,authToken:(null==dr?void 0:dr.accessToken)||""};var ea=Nr(Mt),na={ruleTitle:rt,scopeData:ge,variantsByTier:Array.from(zn.keys()).reduce(function(n,t){var i=zn.get(t)||new Map,r=dt.get(t)||new Map,a=_t.get(t)||new Map,o=gt.get(t)||new Map;return console.log("tier config map",i),n[t]=Array.from(i.keys()).map(function(n,l){var s,u,d=(yt||[])[n]||{};console.log("Original item for tier",t,"index",n,":",d);var c={label:"",isDefault:!1};if(d.is_variant&&!J(d.variant_type))c={label:"",isDefault:!1};else if(re&&re.length>0){c=Pr(re,n,"variantType"),console.log("Found matching variant at index",n,":",c);var v=re[n];if(v){if(!c.label){var _=v.variantType||"",p=J(_);c={label:"variant ".concat(n+1),isDefault:p}}if(v.variantId===tr)(g=d.variant_type||(null==Ft?void 0:Ft.variant_type))&&(c=Gr(g,n),console.log("[templateState] editingVariants[".concat(n,']: using CARE variant_type "').concat(g,'" → label "').concat(c.label,'"')));console.log("Computed variant type at index",n,":",c)}else c={label:Nr(re),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(Mt&&Mt.length>0){if(c=Pr(Mt,n,"variant_type"),console.log("Found matching variant at index",n,":",c),Ke.current){var f=Mt[n];if((null==f?void 0:f.variant_id)===sr||(null==f?void 0:f.variantId)===sr)(g=d.variant_type||(null==Ft?void 0:Ft.variant_type))&&(c=Gr(g,n),console.log("[templateState] existingVariants[".concat(n,']: load-and-edit using CARE variant_type "').concat(g,'" → label "').concat(c.label,'"')))}}else{var g=d.variant_type||"";c={label:ea,isDefault:J(g)}}console.log("Computed variant data for tier",t,"index",n,":",c);var m=null!==(u=null===(s=i.get(n))||void 0===s?void 0:s.is_default_enabled)&&void 0!==u?u:c.isDefault;console.log("live is default :",m);var w="variant ".concat(l+1),y=r.get(n)||"";return{variantId:Jt[n]||d.variant_id||d.variantId,variantType:w,isDefault:m,isModified:d.is_modified,tier:t,index:n,ruleDescription:y.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,""),whenToApplyConditions:(a.get(n)||[]).flatMap(function(n){var t,i=(null===(t=null==n?void 0:n.text)||void 0===t?void 0:t.split(/\s+OR\s+/))||[];return i.length>1?i.map(function(t,i){return e(e({},n),{id:"split-".concat(n.id,"-").concat(i),text:t.trim()})}):[n]}),whenNotToApplyConditions:(o.get(n)||[]).flatMap(function(n){var t,i=(null===(t=null==n?void 0:n.text)||void 0===t?void 0:t.split(/\s+OR\s+/))||[];return i.length>1?i.map(function(t,i){return e(e({},n),{id:"split-".concat(n.id,"-").concat(i),text:t.trim()})}):[n]}),configData:i.get(n)||Kn,isReadOnly:d.is_readOnly||!1,is_variant:d.is_variant||!1,reasoning:{ruleDescription:Er(y),whenToApply:Er(d.wta),whenNotToApply:Er(d.wnta),configData:Er(d.action)}}}),n},{}),citation:li,fieldCitations:gi,citations:di};console.log("templateState",na);var ta={setRuleTitle:function(n){var t,i=void 0!==(null===(t=null==n?void 0:n.target)||void 0===t?void 0:t.value)?n.target.value:n;at(i),Li(function(n){if(n.ruleTitle){var t=e({},n);return delete t.ruleTitle,t}return n})},setRuleDescription:function(e,n,t){return gr(e,n,t)},addWhenToApply:function(e,n){return mr(e,n)},removeWhenToApply:function(e,n,t){return wr(e,n,t)},editWhenToApply:function(e,n,t,i){return yr(e,n,t,i)},addWhenNotToApply:function(e,n){return hr(e,n)},removeWhenNotToApply:function(e,n,t){return br(e,n,t)},editWhenNotToApply:function(e,n,t,i){return Tr(e,n,t,i)},addNewVariant:function(e){return Ar(e)},onScopeChange:Mr,onConfigChange:function(e,n,t,i){return Sr(e,n,t,i)}},ia={},ra={};zn.forEach(function(n,t){ia[t]=new Map,ra[t]=new Map,n.forEach(function(n,i){ia[t].set(i,[e({key:"order_rules",label:"Order"},n.order_rules),e({key:"advertiser_rules",label:"Advertiser"},n.advertiser_rules)]),ra[t].set(i,[{key:"inventory_rules",label:"Inventory code",enabled:n.inventory_rules.respect_inventory_code},{key:"break_code_rules",label:"Break Code",enabled:n.break_code_rules.respect_break_code},{key:"is_default_enabled",label:"Default Variant",enabled:n.is_default_enabled}])})});var aa=v(function(){if(ie){if(1===ge.tiers.length)return 0;var e=ge.tiers.findIndex(function(e){return e.toLowerCase()===ie.toLowerCase()});return e>=0?e:0}},[ie,ge.tiers]),oa=e(e({defaultOpen:!0,tierOptions:["Tier 1","Tier 2"],stationOptions:[{label:"Global Scope",value:"global"},{label:"Genre Scope",value:"genre"},{label:"Custom Scope",value:"custom"}],separationItemsByTier:ia,togglesByTier:ra,highlights:$t,highlightedIds:ni,openSections:Xn,setOpenSections:et,setSendMessageInChat:Pt,isAiStreaming:yi,defaultTierOpen:aa,defaultVariantOpen:mn?void 0:Rt,autoScrollVariantIndex:mn?void 0:Rt,activeVariantAccordionIndex:mn?void 0:Rt,setActiveVariantAccordionIndex:function(e){Dt(e),null!=e&&setTimeout(function(){wn(!1)},100)},validationErrors:Oi,activeEditId:Nn,setActiveEditId:Cn,pendingEditId:En,setPendingEditId:On,conflictReason:Di,usedFor:te||re?"Edit":"Create"},Bn),{scrollTrigger:ri});console.log(Rt,"editVariantIndex checking"),d(function(){},[Z]),d(function(){if(!yi&&Nt&&!!(!te&&!re)){var e=n([],yt,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||yt.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),Dt(e))}},[yi,Nt]);var la=function(){Oe.current&&(clearTimeout(Oe.current),Oe.current=null),Ke.current=!1,$(),kr()},sa=function(){var e={};rt.trim()||(e.ruleTitle="Rule Title is required"),ge.station||(e.station="Station Rule Set is required"),ge.tiers&&0!==ge.tiers.length||(e.tiers="At least one tier must be selected");return ge.tiers.map(function(e){return e.toLowerCase().replace(/ /g,"_")}).forEach(function(n){var t=dt.get(n),i=_t.get(n),r=zn.get(n);r&&Array.from(r.keys()).forEach(function(r){var a=null==t?void 0:t.get(r);a&&a.trim()||(e["ruleDescription-".concat(n,"-").concat(r)]="Rule Description is required");var o=null==i?void 0:i.get(r);o&&o.some(function(e){return""!==e.text.trim()})||(e["whenToApply-".concat(n,"-").concat(r)]='At least one "When to apply" condition is required')})}),e};function ua(r,a,o){var l,s,u,d,c,v;return void 0===o&&(o=!1),t(this,void 0,void 0,function(){var t,_,p,f,g,m,w,y,h,T,A,I,M,S,k,N,C,x,E,O,L,R,D,j;return i(this,function(i){switch(i.label){case 0:if(t=r.question_id,_=(null==r?void 0:r.variant_id)||null,Mn.current&&Pn.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(jn.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",_),Dn(_),_?(-1!==(p=(yt||[]).findIndex(function(e){return e.is_new_variant}))&&(xi(!0),Ki("Removing new variant..."),Zi("Please wait while we remove new variant.")),ht(function(e){if(!Array.isArray(e))return e;var n=e.filter(function(e){return!e.is_new_variant}),t=n.findIndex(function(e){return e.variant_id===_});return-1!==t&&setTimeout(function(){Dt(t),ai(function(e){return e+1}),Ai.current=t},0),n}),-1!==p&&((f=function(e){e(function(e){var n=new Map;return e.forEach(function(e,t){var i=new Map(e);i.delete(p);var r=new Map,a=0;i.forEach(function(e){r.set(a,e),a++}),n.set(t,r)}),n})})(Zn),f(ct),f(pt),f(mt),Ht(function(e){var t=n([],e,!0);return t.length>p&&t.splice(p,1),t})),!1===Mn.current&&(Mn.current=!0,-1!==p&&(null===(l=Ii.current)||void 0===l||l.show({severity:"success",summary:"Success",detail:"New variant removed successfully because you selected to edit an existing variant",life:4e3}))),wn(!1)):(console.log("lastLoadedQuestionIdRef.current in else",jn.current),null===jn.current&&(xi(!0),Ki("Adding new variant..."),Zi("Please wait while we add new variant."))),[2];console.log("User Action: fetching fresh variant info for question",t),Sn.current.clear(),Sn.current.add(t),xi(!0),Ki("Loading variants..."),console.log("reaching here in load and edit"),Zi("Please wait while we fetch the latest variant data."),Mn.current=!0,Pn.current=t,i.label=1;case 1:return i.trys.push([1,5,6,10]),g=Date.now(),[4,b(t,(null==ne?void 0:ne.ruleSetId)||"")];case 2:return m=i.sent(),(w=Date.now()-g)<3e3?[4,new Promise(function(e){return setTimeout(e,3e3-w)})]:[3,4];case 3:i.sent(),i.label=4;case 4:return 0===(y=(null===(s=null==m?void 0:m.data)||void 0===s?void 0:s.variants)||[]).length?(console.warn("No variants found for question_id",t),xi(!1),Ki(""),null===(u=Ii.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(Ke.current=!0,Mn.current=!0,h=(null===(d=null==m?void 0:m.data)||void 0===d?void 0:d.ruleTitle)||"",at(h),T=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,A="tier_1",I="Tier 1",M="1",T&&((S=String(T).match(/(\d+)/))?(k=S[1],M=k,A="tier_".concat(k),I="Tier ".concat(k)):(A=String(T).toLowerCase().trim().replace(/ /g,"_"),I=A.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),M=A.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(I," (ID: ").concat(M,", Key: ").concat(A,")")),me({station:ee||"global",tiers:[I]}),N=function(e,n,t,i,r,a){var o=e.map(function(e){var o,l,s=[t];return{variant_type:e.variantType||"variant",title:n,rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:s,scheduling_config:(null===(o=e.configuration)||void 0===o?void 0:o.scheduling_config)||{},variant_id:e.variantId,question_id:r,tier_id:i,is_readOnly:e.variantId!==a,link_id:e.link_id||"",is_enabled:null===(l=e.is_enabled)||void 0===l||l,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}}),l=new Map,s=new Map,u=new Map,d=new Map;return o.forEach(function(e,n){var t,i,r,a,o,c,v=e.scheduling_config||{};l.set(n,{order_rules:{enabled:!!v.order_global_min_separation_seconds||!!(null===(t=v.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor((v.order_global_min_separation_seconds||(null===(i=v.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!v.advertiser_global_min_separation_seconds||!!(null===(r=v.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor((v.advertiser_global_min_separation_seconds||(null===(a=v.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!v.respect_inventory_code||!!(null===(o=v.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!v.respect_break_code||!!(null===(c=v.break_code_rules)||void 0===c?void 0:c.respect_break_code)},is_default_enabled:J(e.variantType||e.variant_type)}),s.set(n,U(e.rule_description||""));var _=e.wta?e.wta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,_);var p=e.wnta?e.wnta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,p)}),{transformedVariants:o,tierConfigMap:l,tierDescMap:s,tierWtaMap:u,tierWntaMap:d}}(y,h,A,M,t,_),C=N.transformedVariants,x=N.tierConfigMap,E=N.tierDescMap,O=N.tierWtaMap,L=N.tierWntaMap,At(function(e){var n=new Map(e);return n.set(A,JSON.parse(JSON.stringify(C))),n}),ht(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==M});return n(n([],t,!0),C,!0)}),St(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==M});return n(n([],t,!0),C,!0)}),In(!0),jn.current=t,Dn(_),R=0,_&&-1!==(D=C.findIndex(function(e){return e.variant_id===_}))&&(R=D),Dt(R),ai(function(e){return e+1}),Ai.current=R,wn(!1),Zn(function(e){var n=new Map(e);return n.set(A,x),n}),ct(function(e){var n=new Map(e);return n.set(A,E),n}),pt(function(e){var n=new Map(e);return n.set(A,O),n}),mt(function(e){var n=new Map(e);return n.set(A,L),n}),Li({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(v=Ii.current)||void 0===v||v.show({severity:"error",summary:"Error",detail:"Failed to fetch variants. Please try again.",life:3e3}),[3,10];case 6:return Mn.current=!1,xi(!1),Ki(""),Zi(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&jn.current&&Rn?(console.log("inside edit variant flow",jn.current,Rn),ht(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)===Rn?e(e({},n),a):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Rn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Dt(i),ai(function(e){return e+1}),Ai.current=i},0),t}),[3,9]):[3,7];case 7:return(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&jn.current&&!Rn?(console.log("inside add new variant flow",jn.current,Rn),xi(!0),Ki("Adding new variant..."),Zi("Please wait while we add new variant."),[4,new Promise(function(e){return setTimeout(e,3e3)})]):[3,9];case 8:i.sent(),xi(!1),Ki(""),Zi(""),ht(function(t){var i;if(Array.isArray(t)){var r=t.findIndex(function(e){return!0===e.is_new_variant});if(-1!==r)setTimeout(function(){Dt(r),ai(function(e){return e+1}),Ai.current=r},0),i=t.map(function(n,t){return t===r?e(e(e({},n),a),{is_new_variant:!0,is_variant:!0}):n});else{var o=t.length;setTimeout(function(){Dt(o),ai(function(e){return e+1}),Ai.current=o},0),i=n(n([],t,!0),[e(e({},a),{is_new_variant:!0,is_variant:!0})],!1)}}else setTimeout(function(){Dt(0),ai(0),Ai.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return qn.current=i,i}),i.label=9;case 9:return[7];case 10:return[2]}})})}var da;return console.log("RuleSet in render",ne),r(o,{children:[a(g,{ref:Ii}),a(S,{open:Z,chatAssistantName:Hn.ASSISTANT_NAME,organizationName:Hn.ORGANIZATION_NAME,baseUrl:Hn.BASE_URL,baseWebsocketUrl:Hn.BASE_WEBSOCKET_URL,closeFunction:la,ThinkingBulbIconComponent:a(V,{}),customSections:a(o,{}),customMetaData:Be,chatTitle:te?Hn.CHAT_TITLE_EDIT.replace("<scope>",(null==ne?void 0:ne.ruleSetName)||""):Hn.CHAT_TITLE.replace("<scope>",(null==ne?void 0:ne.ruleSetName)||""),formTitle:Hn.FORM_TITLE,showSavedMessage:!1,savedMessage:Me,isError:xe,errorMessage:ke,isSaving:Re,onSave:function(e){console.log("Save this Learning",e);var n=sa();if(Object.keys(n).length>0)return console.log("validation errors",n),void Li(n);De(!0),Ee(!1),Ne("")},showSaveWithoutValidation:!1,onSaveWithoutValidation:function(){return t(void 0,void 0,void 0,function(){var e,n,t,r,a,o,l,s,u;return i(this,function(d){switch(d.label){case 0:return e=sa(),Object.keys(e).length>0?(Li(e),[2]):(console.log("✅ Bypass Save: Initiated"),te||re?[4,Ur()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==Ke.current?[3,4]:[4,Jr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),he(q),n=new Map,t=function(e){var t,r,a,o,l,s;return i(this,function(i){switch(i.label){case 0:if(t=e.toLowerCase().replace(/ /g,"_"),r=Ve.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return n.set(t,null),[2,"continue"];o={question:rt,orgName:Hn.ORGANIZATION_NAME,scope_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),n.set(t,(null===(u=null==l?void 0:l.data)||void 0===u?void 0:u.id)||null),[3,4];case 3:return s=i.sent(),console.error("❌ Bypass Save: Error saving question for ".concat(e,":"),s),n.set(t,null),[3,4];case 4:return[2]}})},r=0,a=ge.tiers,d.label=5;case 5:return r<a.length?(o=a[r],[5,t(o)]):[3,8];case 6:d.sent(),d.label=7;case 7:return r++,[3,5];case 8:return[4,qr(n,!0)];case 9:return d.sent(),[3,11];case 10:return l=d.sent(),he(F),s=new Map,ge.tiers.forEach(function(e){s.set(e.toLowerCase().replace(/ /g,"_"),null)}),qr(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:xr,aiResponse:yt,setAIResponse:ht,width:"90vw",height:"90vh",sendMessageInChat:Vt,template:k.CreateRule,isLoading:ye===q,templateProps:{state:na,handlers:ta,uiState:oa},setSendMessageInChat:Pt,onResetChat:function(){kr()},onResetRequest:function(){ki(!0)},isFormDirty:function(){return""!==rt.trim()||""!==ge.station||ge.tiers.length>0||Array.from(dt.values()).some(function(e){return Array.from(e.values()).some(function(e){return""!==e.trim()})})||Array.from(_t.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Array.from(gt.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||zn.size>0||lt.size>0},initialChatMessage:te?(da=te.ruleTitle||"this rule",null===(z=null==re?void 0:re[null!=ae?ae:0])||void 0===z||z.is_user_accepted_risk,'<p><span>Welcome back! 👋</span>\n <span>I see you want to edit <strong>"'.concat(da,'."</strong></span>\n <span> <strong>What would you like to update? </strong> </span>\n <span>Describe the change you want to make, and I’ll help you edit it.</span>\n </p>')):null!=_e?_e:Hn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(ye===G||Te)return!1;if(!rt||""===rt.trim())return!1;if(null!==Nn)return!1;if(!ge.station||""===ge.station.trim())return!1;var e=ge.tiers&&ge.tiers.filter(function(e){return e&&""!==e.trim()});if(!e||0===(null==e?void 0:e.length))return!1;for(var n,t=0,i=e.map(function(e){return e.toLowerCase().replace(/ /g,"_")});t<i.length;t++){var r=i[t],a=dt.get(r),o=_t.get(r),l=zn.get(r);if(!l||0===l.size)return!1;for(var s=0,u=Array.from(l.keys());s<u.length;s++){var d=u[s],c=null==a?void 0:a.get(d);if(!c||""===c.trim())return!1;var v=null==o?void 0:o.get(d);if(!(null==v?void 0:v.some(function(e){return e.text&&""!==e.text.trim()})))return!1}}return!(!zn||0===zn.size)&&(!(n=function(e){return Array.from(e.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.some(function(e){return!!e.conflict})})})})(_t)&&!n(gt)&&!Xe)},setCitations:ci,isLocked:!0,textareaPlaceholder:"Tell me more about this learning..",saveButtonConfig:{label:te?"Save Changes":"Save Learning",loadingLabel:r("span",e({style:{display:"flex",gap:"5px",alignItems:"center"}},{children:[a(p,{size:20,color:"white",className:"animate-spin"}),a("span",{children:" Saving Changes..."})]}))},setCurrentRequestId:pi,isAiStreaming:yi,setIsAiStreaming:hi,showConfirmReset:Si,setShowConfirmReset:ki,confirmReset:function(){kr(),ki(!1),la()},isLoadingVariants:Ci,mainText:Yi,subText:zi,proposedRule:an,isFetchingComparison:fr,handleOpenComparison:Cr,showComparison:Hi,setShowComparison:Bi,variants:sn,onComparisonLinkClick:pr,targetComparisonVariantId:cn,highlightedComparisonField:pn,onAddAsVariant:function(){Bi(!1)},isCopyEnabled:!0,onSubmitFeedback:function(n){return t(void 0,void 0,void 0,function(){var t,r,a,o,l;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),t=e({user_id:null!==(a=null==dr?void 0:dr._id)&&void 0!==a?a:"",user_name:null!==(o=null==dr?void 0:dr.firstname)&&void 0!==o?o:"",user_email:null!==(l=null==dr?void 0:dr.email)&&void 0!==l?l:"",assistant_name:Hn.ASSISTANT_NAME},n),[4,T(t)];case 1:return i.sent(),[3,3];case 2:throw r=i.sent(),console.error("Failed to submit chat feedback",r),r;case 3:return[2]}})})},handleGlobalClickCapture:function(e){null!==Nn&&(e.target.closest('[data-edit-id="'.concat(Nn,'"]'))||(e.preventDefault(),e.stopPropagation(),On(Nn)))},isGlobalEditActive:null!==Nn,initialDraftMessage:ue?ve:"",socketTimeOutInMilliSeconds:Hn.SOCKET_TIMEOUT})]})};export{B as default,U as filterAgentText};
|
|
2
2
|
//# sourceMappingURL=InstantLearningModal.js.map
|