@e-llm-studio/instant-learning 1.3.0-alpha.2 → 1.3.0-alpha.4
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/AuditLog/AuditLog.js +1 -1
- package/dist/cjs/features/LearningManagement/RuleContent/RuleContent.js +1 -1
- package/dist/cjs/features/LearningManagement/components/CreateLearningSetModal.js +2 -0
- package/dist/cjs/features/LearningManagement/components/CreateLearningSetModal.js.map +1 -0
- package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/cjs/features/LearningManagement/styles/CreateLearningSetModal.module.css.js +2 -0
- package/dist/cjs/features/LearningManagement/styles/CreateLearningSetModal.module.css.js.map +1 -0
- package/dist/features/LearningManagement/AuditLog/AuditLog.js +1 -1
- package/dist/features/LearningManagement/RuleContent/RuleContent.js +1 -1
- package/dist/features/LearningManagement/components/CreateLearningSetModal.js +2 -0
- package/dist/features/LearningManagement/components/CreateLearningSetModal.js.map +1 -0
- package/dist/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/features/LearningManagement/styles/CreateLearningSetModal.module.css.js +2 -0
- package/dist/features/LearningManagement/styles/CreateLearningSetModal.module.css.js.map +1 -0
- package/dist/types/src/features/LearningManagement/AuditLog/AuditLog.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/InstantLearningModal.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 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};
|
|
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 _}from"react";import{AlertTriangle as v,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 y,publishFeedback as w,updateVariant as h,fetchRulesByQuestionId as b,submitChatFeedback as I}from"../apis/scopeApis.js";import T from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as A}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 x,extractAndParseResponse as C,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 P=function(){return a("img",{src:T,alt:"Thinking...",width:"20",height:"20"})},V="INITIAL",G="SUCCESS",F="FAILURE",U="IN_PROGRESS",q=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")},Y=function(T){var Y,B,W,K,Q,z,Z=T.isOpen,$=T.onClose,X=T.initialScope,ee=void 0===X?"global":X,ne=T.ruleSet,te=T.editingRule,ie=T.editingTier,re=T.editingVariants,ae=T.focusedVariantIndex,oe=T.setFocusedVariantIndex,le=T.triggerAddVariant,se=T.triggerFixGaps,ue=T.copiedRule,de=T.copiedSourceTier,ce=T.copiedTargetTier,_e=T.initialDraftMessage,ve=T.initialChatMessage,pe=T.applicationIntegrationId;T.modeId;var fe=s({station:ee,tiers:["Tier 1"]}),ge=fe[0],me=fe[1],ye=s(V),we=ye[0],he=ye[1],be=s(!1),Ie=be[0],Te=be[1],Ae=s("Thank you teacher for teaching me, your rule has been saved successfully."),Me=Ae[0];Ae[1];var Se=s(""),ke=Se[0],Ne=Se[1],xe=s(!1),Ce=xe[0],Ee=xe[1],Oe=u(null),Le=s(!1),Re=Le[0],De=Le[1],je=u(!1),Pe=A().tiers,Ve=l.useRef(new Set),Ge=s(null);Ge[0];var Fe=Ge[1],Ue=s(null);Ue[0];var qe=Ue[1],Je=s(null);Je[0];var He=Je[1],Ye=u({}),Be=u(new Map),We=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],_n=dn[1],vn=s(null),pn=vn[0],fn=vn[1],gn=s(!1),mn=gn[0],yn=gn[1],wn=u({}),hn=u([]),bn=u(!1),In=s(!1),Tn=In[0],An=In[1],Mn=u(!1),Sn=u(new Set),kn=s(null),Nn=kn[0],xn=kn[1],Cn=s(null),En=Cn[0],On=Cn[1],Ln=s(null),Rn=Ln[0],Dn=Ln[1],jn=u(null),Pn=u(null),Vn=u(null),Gn=u({}),Fn=u([]),Un=u([]),qn=u({}),Jn=R(),Hn=Jn.configuration,Yn=Jn.ilLabels,Bn=A.getState().backwardCompatibility,Wn=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(wt,"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]})}),Pn.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,_=[];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),_.push(e.variantId||e.variant_id||"")}),o.set(a,u),l.set(a,d),s.set(a,c);var v=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!==v,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),Tt(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,y=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:y>0,global_min_separation_seconds:Math.floor(y/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!==(v=null===(_=null==g?void 0:g.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==v?v: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 y=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,y]])]]))}}}else if(ue&&de&&ce){at(ue.ruleTitle||""),me(function(n){return e(e({},n),{tiers:[ce]})}),Pn.current=H(ce);var w=H(de),h=ue.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),I=new Map,T=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:""}}):[];I.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:""}}):[];T.set(n,i)}),o.set(w,b),l.set(w,I),s.set(w,T),ct(o),pt(l),mt(s);var A=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:w.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(A),St(A),Tt(function(e){var n=new Map(e);return n.set(w,JSON.parse(JSON.stringify(A))),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!==(v=null===(_=null==f?void 0:f.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==v?v:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:J(e.variantType||e.variant_type)})}),Zn(new Map([[w,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," ");Vt("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&&Vt("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],_t=s(new Map([["tier_1",new Map],["tier_2",new Map]])),vt=_t[0],pt=_t[1],ft=s(new Map([["tier_1",new Map],["tier_2",new Map]])),gt=ft[0],mt=ft[1],yt=s([]),wt=yt[0],ht=yt[1],bt=s(new Map),It=bt[0],Tt=bt[1],At=s([]),Mt=At[0],St=At[1],kt=s(!1),Nt=kt[0],xt=kt[1],Ct=s([]),Et=Ct[0],Ot=Ct[1],Lt=s(void 0),Rt=Lt[0],Dt=Lt[1],jt=s(""),Pt=jt[0],Vt=jt[1],Gt=s(null),Ft=Gt[0],Ut=Gt[1],qt=s([]),Jt=qt[0],Ht=qt[1],Yt=s([]),Bt=Yt[0],Wt=Yt[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],_i=s(""),vi=_i[0],pi=_i[1],fi=s({}),gi=fi[0],mi=fi[1],yi=s(!1),wi=yi[0],hi=yi[1],bi=u(null),Ii=u(null),Ti=u(-1),Ai=u(null);d(function(){Un.current=wt},[wt]),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=Ai.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(v,{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),xi=Ni[0],Ci=Ni[1],Ei=s({}),Oi=Ei[0],Li=Ei[1],Ri=s(""),Di=Ri[0],ji=Ri[1],Pi=s(!0),Vi=Pi[0],Gi=Pi[1],Fi=s(!1),Ui=Fi[0],qi=Fi[1],Ji=s(!1),Hi=Ji[0],Yi=Ji[1],Bi=s(""),Wi=Bi[0],Ki=Bi[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(),_r=cr.dispatch,vr=cr.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",wt)},[wt]),d(function(){console.log("isCloseModal AI Response updated:",Vi)},[Vi]),d(function(){!1===wi?(Ci(!1),Ki(""),Zi("")):(Ee(!1),Ne(""))},[wi]),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");Vt("Save this Learning"),De(!1),setTimeout(function(){je.current=!1,Vt("")},2e3)}},[Re]);var pr=c(function(e,n){sn.some(function(n){return n.id===e})?(Yi(!0),_n(e),fn(n),setTimeout(function(){fn(null),_n(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[sn]),fr=_(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})},[]),yr=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})},[]),wr=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})},[]),Ir=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})},[]),Tr=c(function(e){var n=e.replace(/_/g," ");yn(!0),null==oe||oe(null),Dt(void 0),Vt("I want to add a new variant to ".concat(n))},[]),Ar=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(){wi&&(Yi(!1),fn(null),_n(null))},[wi]);var kr=c(function(n){var t;if(void 0===n&&(n=!1),n||(_r({type:"RESET"}),bi.current=null,ht([]),Ot([]),ci([]),mi({}),Yi(!1),Ve.current.clear()),at(""),Ht([]),yn(!1),We.current="",er(""),or(null),Wt([]),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]])),Vt(""),si({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Li({}),ji(""),Gi(!0),Fe(null),qe(null),Tt(new Map),St([]),An(!1),He(null),Ii.current=null,Ke.current=!1,wn.current={},Sn.current.clear(),jn.current=null,Pn.current=null,Dn(null),Ne(""),he(V),Te(!1),Ee(!1),De(!1),on(null),un([]),_n(null),fn(null),xn(null),xt(!1),Ut(null),Ki(""),Zi(""),Ci(!1),et(new Set),je.current=!1,Be.current.clear(),tn.current=0,nn.current=null,Vn.current=null,Ti.current=-1,Mn.current=!1,bn.current=!1,te){te.ruleTitle&&at(te.ruleTitle),ie&&(me(function(n){return e(e({},n),{tiers:[ie]})}),Pn.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),Tt(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var _=new Map;re.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,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,y=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;_.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:y>0,global_min_separation_seconds:Math.floor(y/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===(v=null==g?void 0:g.break_code_rules)||void 0===v?void 0:v.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,_]])),Dt(null!=ae?ae:0)}}},[_r,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)},xr=c(function(){console.log("variantIds",Jt),Yi(!0)},[Jt]),Cr={"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;Ti.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),Dt(r),Ti.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&&Pn.current!==u);if(d&&u){var c=Pn.current;console.log("[Tier Switch Detected]",Pn.current,"→",u),Pn.current=u,jn.current=null;var _=(Un.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===_&&void 0!==Rt&&(_=Rt),c&&-1!==_&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(_," from ").concat(c)),ct(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),pt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),mt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),Zn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),ht(function(t){if(!Array.isArray(t))return t;var i=n([],t,!0);return i[_]&&(i[_]=e(e({},i[_]),{scope:[u],tier_id:u.replace("tier_","")})),Un.current=i,i})),Ti.current=-1;var v=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});me(function(n){return e(e({},n),{tiers:[v]})})}Ut(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}),Ti.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}),Ti.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}),Ti.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}),Ti.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return Un.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(ht([r]),setTimeout(function(){Dt(0),ai(function(e){return e+1}),Ti.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=x(t)}if(qe(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){Ut(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(wt)){var r=tr||ar,a=-1;!(!te&&!re)&&r&&(a=wt.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=wt[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=Un.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=C(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),qi(!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),xn(null),An(!1),yn(!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),_n(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?C(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),_=void 0===(null==u?void 0:u.close_modal)||!!(null==u?void 0:u.close_modal),v=void 0!==(null==u?void 0:u.is_save)&&!!(null==u?void 0:u.is_save);Gi(_),qi(v);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(Ii.current=null);er(p);var m=null==u?void 0:u.new_variant_id,y="edit"===(null==u?void 0:u.action)&&(null==u?void 0:u.set_variant_id)&&!re;(null==u?void 0:u.is_valid)?(Li({}),Ut(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)},y=e(e({},t),u);Array.isArray(null===(i=null==u?void 0:u.condition_result)||void 0===i?void 0:i.when_to_apply)?y.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)&&(y.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)?y.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)&&(y.wnta=null!==(o=null==u?void 0:u.wnta)&&void 0!==o?o:""),console.log("finalData",y),console.log("checking parsed here :",u);var w,h=f;if(Array.isArray(wt)&&h&&(w=h,wt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===w||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===w||(null==e?void 0:e.id)&&e.id===w})),"edit"!==(null==u?void 0:u.action)||!te&&!re)return y;console.log("inside edit flow merge");var b=re||[],I=f,T=I?b.findIndex(function(e){return e.variantId===I||e.variant_id&&e.variant_id===I||e.id&&e.id===I}):-1;if(-1===T&&(null==u?void 0:u.set_variant_id)&&(T=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===T&&I&&Array.isArray(wt)&&(T=wt.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===I||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===I||(null==e?void 0:e.id)&&e.id===I})),-1!==T){var A,M,S,k=b[T]||(null==wt?void 0:wt[T]),N=(null==k?void 0:k.tier_id)||(null==k?void 0:k.tierId)||"1",x=(null==ie?void 0:ie.toLowerCase().replace(/ /g,"_"))||"tier_".concat(N);if(Ti.current!==T&&(Dt(T),Ti.current=T),Array.isArray(null===(l=u.condition_result)||void 0===l?void 0:l.when_to_apply)?A=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)?A=null!==(s=null==u?void 0:u.wta)&&void 0!==s?s:"":m(t,"wta")&&void 0!==(null==t?void 0:t.wta)&&(A=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!==(_=null==u?void 0:u.wnta)&&void 0!==_?_:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(M=null!==(v=null==t?void 0:t.wnta)&&void 0!==v?v:""),void 0!==A){var C=Or(A);Lr(x,T,A,C,vt,pt,null==u?void 0:u.conflict_view),Ar(x,T,"wta")}if(void 0!==M){var E=Or(M);Lr(x,T,M,E,gt,mt,null==u?void 0:u.conflict_view),Ar(x,T,"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(x)||new Map);return t.set(T,O),n.set(x,t),n}),Ar(x,T,"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(x)||new Map);return u.set(T,{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(x,u),s}),Ar(x,T,"order_enabled"),Ar(x,T,"advertiser_enabled"),Ar(x,T,"respect_inventory_code"),Ar(x,T,"respect_break_code")),ht(function(t){if(!Array.isArray(t)||T<0||!t[T])return t;var i=n([],t,!0),r=e({},i[T]);return void 0!==A&&(r.wta=A),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[T]=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===I||(null==e?void 0:e.variant_id)&&e.variant_id===(null==u?void 0:u.set_variant_id)||(null==e?void 0:e.variantId)===I});return-1!==r?i[r]=e(e({},i[r]),{variant_type:R}):i[T]=e(e({},i[T]||{}),{variant_type:R,variant_id:I||(null==u?void 0:u.set_variant_id)}),i})}})):console.warn("⚠️ parsed.is_valid is false, not committing to structuredAIResponse"),y||(c?(xt(!0),m&&m!==Ii.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),Ci(!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."),Ii.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(xt(!1),Ii.current=null),d&&Ht(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&&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=C(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 _="";if((null==o?void 0:o.nodes)&&o.nodes.title){var v=o.nodes.title;(null===(i=null===(t=null==v?void 0:v.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:_,extractedScore:p,extractedScope:f}),{id:u,title:_,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"),_=(null===(u=d[(null==d?void 0:d.length)-1])||void 0===u?void 0:u.reasoning)||"",v=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=[],_=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==_?void 0:_.find(function(e){return e.value===o}),v=u.get(i);if(v)c.push(e(e({},v),{reasoning:r||v.reasoning,conflict:s||v.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(){Pt&&!je.current&&"save this learning"!==Pt.toLowerCase()&&(Ee(!1),Ne(""),Ti.current=null!=Rt?Rt:-1)},[Pt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Fn.current=di,Array.isArray(wt)&&wt.length>0){var c=vi||"local-".concat(Date.now()),_=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],v={},p=bi.current||[];wt.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===wt.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&&(Ar(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),y=(null===(l=dt.get(r))||void 0===l?void 0:l.get(o))||"",w=Or(y);g&&(m!==w||""===m&&""!==y)&&(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}),Ar(r,o,"ruleDescription"));var h=!1===(null==Ft?void 0:Ft.is_valid),b=Or(t.wta),I=Or(null==c?void 0:c.wta),T=(null===(s=vt.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&T.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==I||""===b&&T.length>0||0===T.length&&""!==b)&&(Lr(r,o,t.wta,b,vt,pt,null==Ft?void 0:Ft.conflict_view),Ar(r,o,"wta"));var A=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&&""===A&&S.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(A!==M||""===A&&S.length>0||0===S.length&&""!==A)&&(Lr(r,o,t.wnta,A,gt,mt,null==Ft?void 0:Ft.conflict_view),Ar(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,x=null===(d=zn.get(r))||void 0===d?void 0:d.get(o),C=t.variant_type||t.variantType,E=C?J(C):void 0,O=JSON.stringify(k)!==JSON.stringify(N),L=void 0!==E&&E!==(null==x?void 0:x.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 Ar(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),_=c.get(o)||Kn;return c.set(o,e(e(e(e(e(e({},_),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||_.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,qn.current[t]=!0,v[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,y=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},w=function(e,n){if(!n)return-1;var t=e.find(function(e){return y(e,n)});if(!t)return-1;var i=String((null==t?void 0:t.tier_id)||"");if(!i)return e.findIndex(function(e){return y(e,n)});var r=e.filter(function(e){return String((null==e?void 0:e.tier_id)||"")===i}).findIndex(function(e){return y(e,n)});return-1!==r?r:e.findIndex(function(e){return y(e,n)})};if(g)if(Ii.current&&Nt)-1!==(f=wt.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===Ii.current||(null==e?void 0:e.variant_id)&&e.variant_id===Ii.current||(null==e?void 0:e.id)&&e.id===Ii.current}))&&(Ii.current=null);else if(tr||ar){var h;(h=tr||ar)&&(f=w(wt,h))}else if(le&&Array.isArray(wt)&&wt.length>0){for(b=wt.length-1;b>=0;b--)if(wt[b]&&!(null===(i=wt[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||Ii.current)&&m&&(f=w(wt,h)),!m&&-1===f&&Array.isArray(wt)&&wt.length>0){for(var b=wt.length-1;b>=0;b--)if(wt[b]&&!(null===(t=wt[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=wt.length-1)}-1!==f&&Rt!==f&&(Ti.current===f||Ke.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),Dt(f),Ti.current=f));var I=wt[0];if(I){if(I.scope&&JSON.stringify(I.scope)!==JSON.stringify(null===(r=p[0])||void 0===r?void 0:r.scope)&&"copy"!==I.action&&(l=I.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)||Ar("global",0,"scope_".concat(n))})),I.scope_rule_set&&I.scope_rule_set!==(null===(o=p[0])||void 0===o?void 0:o.scope_rule_set)){var T=I.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(T)&&(me(function(n){return e(e({},n),{station:T})}),Ar("global",0,"scope_station"))}I.wtl&&tt(I.wtl)}bi.current=wt.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(v).length>0&&(_r({type:"SAVE_CITATIONS",requestId:c,reasoningMap:v,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(v),newReasoningMap:v,getLatestReasoning:vr,currentCitations:di}),si(function(n){var t=e({},n),i=!1;return Object.keys(v).forEach(function(e){var n=v[e];n.reasoning&&t[e]!==n.reasoning&&(t[e]=n.reasoning,i=!0),n.associatedCitations}),i?t:n}))}},[wt,di,vi]),d(function(){var t=Object.keys(qn.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],di,!0)}),qn.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=Bn?{respect_break_code:"bool",override_priority_code:"str",respect_inventory_code:"bool",custom_sep_time_for_entities:"object",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",advertiser_pair_break_constraint:"array",order_exemption_product_code_list:"array",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",order_global_min_separation_seconds:"int",product_exemption_product_code_list:"array",advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",inventory_exemption_product_code_list:"array",advertiser_exemption_product_code_list:"array",break_code_exemption_product_code_list:"array",inventory_exemption_priority_code_list:"array",advertiser_exemption_priority_code_list:"array",break_code_exemption_priority_code_list:"array",advertiser_global_min_separation_seconds:"int",first_in_break_condition_advertiser_list:"array",first_in_break_condition_break_code_list:"array",first_in_break_exemption_advertiser_list:"array",first_in_break_exemption_break_code_list:"array",max_priority_override_priority_code_list:"array",first_in_break_condition_product_code_list:"array",first_in_break_exemption_product_code_list:"array",first_in_break_condition_priority_code_list:"array",first_in_break_exemption_priority_code_list:"array",max_priority_override_exemption_advertiser_list:"array",max_priority_override_exemption_break_code_list:"array",max_priority_override_exemption_product_code_list:"array",max_priority_override_exemption_priority_code_list:"array",first_in_segment_condition_advertiser_list:"array",first_in_segment_condition_break_code_list:"array",first_in_segment_exemption_advertiser_list:"array",first_in_segment_exemption_break_code_list:"array",first_in_segment_condition_product_code_list:"array",first_in_segment_exemption_product_code_list:"array",first_in_segment_condition_priority_code_list:"array",first_in_segment_exemption_priority_code_list:"array"}:{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"},t={};return Object.entries(e).forEach(function(e){var n,i=e[0],r=e[1];if("custom_sep_time_for_entities"===i&&r)t.custom_sep_time_for_entities=r;else if("max_priority_override"===i&&r&&void 0!==r.override_priority_code)t.override_priority_code=r.override_priority_code;else if("advertiser_pair_break_constraint"===i&&r)t.advertiser_pair_break_constraint=r.advertiser_pair_list;else if(r&&"object"==typeof r&&(null===(n=Object.keys(r))||void 0===n?void 0:n.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 n=e[0],r=e[1];if(o.includes(n)&&("product_rules"!==i||"global_min_separation_seconds"!==n)){var l="respect_inventory_code"===n||"respect_break_code"===n?n:"".concat(a,"_").concat(n);t[l]=r}})}else if(void 0!==r&&"object"!=typeof r){if("station_guid"===i||"is_default_enabled"===i)return;t[i]=r}}),{config_structure:{scheduling_config:n},config_data:{scheduling_config:t}}},Pr=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 _=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:_})}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},Vr=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"},Ur=function(n,o){return void 0===o&&(o=!1),t(void 0,void 0,void 0,function(){var t,l,s,u,d,c,_,p,g,y,h,b,I,T,S,k,N;return i(this,function(i){switch(i.label){case 0:t=Dr(ge.tiers),l=A.getState().backwardCompatibility,s=tn.current,u=Pr(lt,Qt,zn,s),i.label=1;case 1:return i.trys.push([1,3,,4]),he(U),Ne(""),d=jr(u),c=m(),_=[],p=[],g=(wt||[])[s]||{},console.log("originalItem check :",g,s),ge.tiers.forEach(function(i){var r,a,o,u,v,f,y,h,b,I,T,A,M,S,k,N,x,C,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=vt.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===(v=null===(u=zn.get(E))||void 0===u?void 0:u.get(s))||void 0===v?void 0:v.is_default_enabled)||void 0===f||f,tier_id:(null===(y=Pe.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===E||e.tier_name.toLowerCase()===E.replace(/_/g,"")}))||void 0===y?void 0:y.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"})];_.push(w(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===(A=null===(T=null===(I=zn.get(E))||void 0===I?void 0:I.get(s))||void 0===T?void 0:T.is_default_enabled)||void 0===A||A,tier:{name:i.split(" ").join("").toLowerCase(),tierGroupName:j.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(M=Pe.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==Wn?void 0:Wn.applicationId)&&void 0!==N?N:"",scopeLevelModuleId:(null==Wn?void 0:Wn.moduleId)||"",applicationLevelModuleId:null!==(x=null==Wn?void 0:Wn.applicationModuleId)&&void 0!==x?x:"",applicationLevelResourceId:null!==(C=null==Wn?void 0:Wn.applicationResourceId)&&void 0!==C?C:""}};_.push(w(D,Hn.ASSISTANT_NAME))}}),[4,Promise.all(_)];case 2:return y=i.sent(),De(!1),console.log("✅ All feedback published:",y),he(G),Te(!0),h=new Map,y.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)}}),A.getState().setCreatedVariantInfo(Array.from(h.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(S=Ai.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(){Vi||o?(console.log("Closing modal after save success",{isCloseModal:Vi,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),I=(null===(k=null==b?void 0:b.response)||void 0===k?void 0:k.data)||{},console.log("errorData: ",I),(T="Variant already exists"===(null==I?void 0:I.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==I?void 0:I.message)||(null==I?void 0:I.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(N=Ai.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(v,{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:T||409===(null==b?void 0:b.status)?"Similar rule already exists. Please update and try again.":(null==I?void 0:I.message)||(null==I?void 0:I.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 t,o,l,s,u,d,c,_,p,g,y,b,I,T,S,k,N,x,C,E,O,L,R,D,j,P;return i(this,function(i){switch(i.label){case 0:t=A.getState().tiers,o=Pr(lt,Qt,zn),l=jr(o),s=tn.current,u=(wt||[])[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(U),Ne(""),_=(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,y=n([],c,!0),b=c.length;b<g;b++)y.push({isNewVariant:!0,variantId:m()});return I=[],T=[],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=vt.get(i),s=gt.get(i);y.forEach(function(t,c){var v,p,f,g,y,b,A,M,k,N,x,C,E,O,L,R,D,j,P,V,G,F,U,H,Y,B,W,K,Q,z,Z,$,X,ee,ie,re,ae,oe,le,se=(null==a?void 0:a.get(c))||t.description||"",ue=(null==o?void 0:o.get(c))||[],de=(null==s?void 0:s.get(c))||[];if(t.isNewVariant){T.push({tierKey:i,payloadType:"new"});var ce=Pr(lt,Qt,zn,c),_e=jr(ce);if(console.log("variant in save edit add part :",t,u),!1===Bn){var ve={status:"approved",metadata:e(e({userName:null!==(v=null==dr?void 0:dr.firstname)&&void 0!==v?v:"",userEmailId:null!==(p=null==dr?void 0:dr.email)&&void 0!==p?p:"",llm:Hn.MODEL,isVariantFlow:!0},_e&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},_e)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:_||m(),variant:Or(se),conditions_whentoapply:ue.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:de.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!==(y=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!==y?y: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===(A=(wt||[])[c])||void 0===A?void 0:A.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)",ve),I.push(w(ve,Hn.ASSISTANT_NAME))}else{ve={status:"approved",metadata:e(e({userName:null!==(k=null==dr?void 0:dr.firstname)&&void 0!==k?k:"",userEmailId:null!==(N=null==dr?void 0:dr.email)&&void 0!==N?N:"",llm:Hn.MODEL,isVariantFlow:!0},_e&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},_e)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:_||m(),variant:Or(se),conditions_whentoapply:ue.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:de.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!==(E=null===(C=null===(x=zn.get(i))||void 0===x?void 0:x.get(c))||void 0===C?void 0:C.is_default_enabled)&&void 0!==E?E: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!==(O=null==dr?void 0:dr.email)&&void 0!==O?O:"",instantLearningType:Hn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(R=null===(L=(wt||[])[c])||void 0===L?void 0:L.is_user_accepted_risk)&&void 0!==R?R:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0}),appsecData:{application:null!==(D=null==Wn?void 0:Wn.applicationId)&&void 0!==D?D:"",scopeLevelModuleId:(null==Wn?void 0:Wn.moduleId)||"",applicationLevelModuleId:null!==(j=null==Wn?void 0:Wn.applicationModuleId)&&void 0!==j?j:"",applicationLevelResourceId:null!==(P=null==Wn?void 0:Wn.applicationResourceId)&&void 0!==P?P:""}};console.log("payload (publish new variant)",ve),I.push(w(ve,Hn.ASSISTANT_NAME))}}else{T.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var pe=t.variantId===tr,fe=Fr(i,c,pe?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",fe,pe,t,tr);var me={variantId:t.variantId,ruleDesc:(null==ne?void 0:ne.ruleSetDesc)||"",whenToApply:ue.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:de.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(F=null===(G=null===(V=zn.get(i))||void 0===V?void 0:V.get(c))||void 0===G?void 0:G.is_default_enabled)&&void 0!==F?F: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!==(U=null==r?void 0:r.tier_priority)&&void 0!==U?U:null},scope_id:(null==ne?void 0:ne.ruleSetId)||"",description:Or(se)||"",topic:"".concat(ge.station,"RuleSet"),configuration:(null==l?void 0:l.config_data)||{},tierLinkId:null!=_?_:null,variantType:fe,is_user_accepted_risk:!!(null!==(Y=null===(H=(wt||[])[c])||void 0===H?void 0:H.is_user_accepted_risk)&&void 0!==Y?Y:null==t?void 0:t.is_user_accepted_risk),is_enabled:t.is_enabled},ye=(It.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===t.variantId}),we=!0;if(ye){var he=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},be=he(rt)===he(ye.title),Ie=he(se)===he(ye.rule_description),Te=he(me.whenToApply)===he(ye.wta),Ae=he(me.whenNotToApply)===he(ye.wnta),Me=!!me.isDefault===J(ye.variant_type),Se=ye.scheduling_config||{},ke=null!==(K=null!==(B=Se.order_global_min_separation_seconds)&&void 0!==B?B:null===(W=Se.order_rules)||void 0===W?void 0:W.global_min_separation_seconds)&&void 0!==K?K:0,Ne=null!==(Z=null!==(Q=Se.advertiser_global_min_separation_seconds)&&void 0!==Q?Q:null===(z=Se.advertiser_rules)||void 0===z?void 0:z.global_min_separation_seconds)&&void 0!==Z?Z:0,xe=null!==(ee=null!==(X=null===($=Se.inventory_rules)||void 0===$?void 0:$.respect_inventory_code)&&void 0!==X?X:Se.respect_inventory_code)&&void 0!==ee&&ee,Ce=null!==(ae=null!==(re=null===(ie=Se.break_code_rules)||void 0===ie?void 0:ie.respect_break_code)&&void 0!==re?re:Se.respect_break_code)&&void 0!==ae&&ae,Ee=(null===(oe=zn.get(i))||void 0===oe?void 0:oe.get(c))||Kn,Oe=Ee.order_rules.enabled===ke>0&&Ee.order_rules.global_min_separation_seconds===Math.floor(ke/60)&&Ee.advertiser_rules.enabled===Ne>0&&Ee.advertiser_rules.global_min_separation_seconds===Math.floor(Ne/60)&&Ee.inventory_rules.respect_inventory_code===xe&&Ee.break_code_rules.respect_break_code===Ce;be&&Ie&&Te&&Ae&&Me&&Oe&&(we=!1)}we?(console.log("payloadv (update existing variant)",me),I.push(h(me,null!==(le=null==dr?void 0:dr.email)&&void 0!==le?le:""))):(console.log("[saveEditedVariant] No changes for variant ".concat(t.variantId,", skipping API call")),I.push(Promise.resolve({data:{id:t.variantId},skipped:!0})))}})}),[4,Promise.all(I)];case 2:return k=i.sent(),console.log("✅ All variants updated:",k),he(G),Te(!0),De(!1),N=new Map,k.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=T[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)}}}),A.getState().setCreatedVariantInfo(Array.from(N.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=Ai.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 x=i.sent(),console.error("❌ Error updating variant:",x),he(F),Ee(!0),De(!1),C=(null===(j=null==x?void 0:x.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",C),(E="Variant already exists"===(null==C?void 0:C.message))||409===(null==x?void 0:x.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==C?void 0:C.message)||(null==C?void 0:C.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(P=Ai.current)||void 0===P||P.show({severity:"error",sticky:!1,className:M.toastError,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(v,{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==x?void 0:x.status)?"Similar rule already exists. Please update and try again.":(null==C?void 0:C.message)||(null==C?void 0:C.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,_,p,g,y,b,I,T,S,k,N,x,C,E,O,L,R,D,j,P;return i(this,function(i){switch(i.label){case 0:n=A.getState().tiers,t=Pr(lt,Qt,zn),o=jr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),he(U),Ne(""),0===(l=Array.isArray(wt)?wt:[]).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=[],_=[],p=[],g=[],y=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=vt.get(i),u=gt.get(i);l.forEach(function(n,l){var v,f,w,b,I,T,A,M,S,k,N,x,C,E,O,L,R,D,j,P,V,G,F,U,H,Y,B,W,K,Q,z,Z,$,X,te,ie,re,ae=(null==a?void 0:a.get(l))||n.rule_description||n.description||"",oe=(null==s?void 0:s.get(l))||[],le=(null==u?void 0:u.get(l))||[];if(n.is_new_variant){var se=Pr(lt,Qt,zn,l),ue=jr(se),de=Fr(i,l,n.variant_type||n.variantType||"");if(console.log("Debug 5000"),!1===Bn){var ce={status:"approved",metadata:e(e({userName:null!==(v=null==dr?void 0:dr.firstname)&&void 0!==v?v:"",userEmailId:null!==(f=null==dr?void 0:dr.email)&&void 0!==f?f:"",llm:Hn.MODEL,isVariantFlow:!0},ue&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},ue)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Or(ae),conditions_whentoapply:oe.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:le.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:y[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!==(I=null===(b=null===(w=zn.get(i))||void 0===w?void 0:w.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==I?I: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:de,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(T=null==dr?void 0:dr.email)&&void 0!==T?T:"",instantLearningType:Hn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(A=null==n?void 0:n.is_user_accepted_risk)&&void 0!==A?A:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ce),_.push({payload:ce,tierKey:i}),g.push({tierKey:i})}else{ce={status:"approved",metadata:e(e({userName:null!==(M=null==dr?void 0:dr.firstname)&&void 0!==M?M:"",userEmailId:null!==(S=null==dr?void 0:dr.email)&&void 0!==S?S:"",llm:Hn.MODEL,isVariantFlow:!0},ue&&{config:e({master_name:Hn.CONFIG_MASTER_NAME},ue)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Or(ae),conditions_whentoapply:oe.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:le.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:y[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!==(x=null===(N=null===(k=zn.get(i))||void 0===k?void 0:k.get(l))||void 0===N?void 0:N.is_default_enabled)&&void 0!==x?x: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:de,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(C=null==dr?void 0:dr.email)&&void 0!==C?C:"",instantLearningType:Hn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(E=null==n?void 0:n.is_user_accepted_risk)&&void 0!==E?E:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0}),appsecData:{application:null!==(O=null==Wn?void 0:Wn.applicationId)&&void 0!==O?O:"",scopeLevelModuleId:(null==Wn?void 0:Wn.moduleId)||"",applicationLevelModuleId:null!==(L=null==Wn?void 0:Wn.applicationModuleId)&&void 0!==L?L:"",applicationLevelResourceId:null!==(R=null==Wn?void 0:Wn.applicationResourceId)&&void 0!==R?R:""}};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ce),_.push({payload:ce,tierKey:i}),g.push({tierKey:i})}}else if(null==n?void 0:n.variant_id){p.push({tierKey:i,existingId:n.variant_id});var _e=(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||"",ve=(de=Fr(i,l,_e),{variantId:n.variant_id,ruleDesc:(null==ne?void 0:ne.ruleSetDesc)||"",whenToApply:oe.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),whenNotToApply:le.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null!==(P=null===(j=null===(D=zn.get(i))||void 0===D?void 0:D.get(l))||void 0===j?void 0:j.is_default_enabled)&&void 0!==P?P: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!==(V=null==r?void 0:r.tier_priority)&&void 0!==V?V:null},scope_id:(null==ne?void 0:ne.ruleSetId)||"",description:Or(ae)||"",topic:"".concat(ge.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:de,is_user_accepted_risk:!!(null!==(G=null==n?void 0:n.is_user_accepted_risk)&&void 0!==G?G:null===(F=(wt||[])[l])||void 0===F?void 0:F.is_user_accepted_risk),is_enabled:n.is_enabled}),pe=(It.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===(null==n?void 0:n.variant_id)}),fe=!0;if(pe){var me=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ye=me(rt)===me(pe.title),we=me(ae)===me(pe.rule_description),he=me(ve.whenToApply)===me(pe.wta),be=me(ve.whenNotToApply)===me(pe.wnta),Ie=!!ve.isDefault===J(pe.variant_type),Te=pe.scheduling_config||{},Ae=null!==(Y=null!==(U=Te.order_global_min_separation_seconds)&&void 0!==U?U:null===(H=Te.order_rules)||void 0===H?void 0:H.global_min_separation_seconds)&&void 0!==Y?Y:0,Me=null!==(K=null!==(B=Te.advertiser_global_min_separation_seconds)&&void 0!==B?B:null===(W=Te.advertiser_rules)||void 0===W?void 0:W.global_min_separation_seconds)&&void 0!==K?K:0,Se=null!==(Z=null!==(z=null===(Q=Te.inventory_rules)||void 0===Q?void 0:Q.respect_inventory_code)&&void 0!==z?z:Te.respect_inventory_code)&&void 0!==Z&&Z,ke=null!==(te=null!==(X=null===($=Te.break_code_rules)||void 0===$?void 0:$.respect_break_code)&&void 0!==X?X:Te.respect_break_code)&&void 0!==te&&te,Ne=(null===(ie=zn.get(i))||void 0===ie?void 0:ie.get(l))||Kn,xe=Ne.order_rules.enabled===Ae>0&&Ne.order_rules.global_min_separation_seconds===Math.floor(Ae/60)&&Ne.advertiser_rules.enabled===Me>0&&Ne.advertiser_rules.global_min_separation_seconds===Math.floor(Me/60)&&Ne.inventory_rules.respect_inventory_code===Se&&Ne.break_code_rules.respect_break_code===ke;ye&&we&&he&&be&&Ie&&xe&&(fe=!1)}fe?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ve),c.push(h(ve,null!==(re=null==dr?void 0:dr.email)&&void 0!==re?re:""))):(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),I=[],T=0,S=_,i.label=3;case 3:if(!(T<S.length))return[3,8];k=S[T],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,w(k.payload,Hn.ASSISTANT_NAME)];case 5:return N=i.sent(),I.push(N),[3,7];case 6:throw x=i.sent(),console.error("❌ Error publishing new variant:",x),x;case 7:return T++,[3,3];case 8:return console.log("✅ All new variants published:",I),C=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=C.get(r.tierKey)||[];l.push({id:o,action:"existing"}),C.set(r.tierKey,l)}}}),I.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=C.get(r.tierKey)||[];o.push({id:a,action:"new"}),C.set(r.tierKey,o)}}),A.getState().setCreatedVariantInfo(Array.from(C.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),he(G),Te(!0),De(!1),Ke.current=!1,null===(D=Ai.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===(P=Ai.current)||void 0===P||P.show({severity:"error",sticky:!1,className:M.toastError,content:r("div",e({className:M.toastContent},{children:[r("div",e({className:M.toastHeaderLeft},{children:[a(v,{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(){Ui&&!wi&&(console.log("isSaveRule received from agent — calling publish APIs directly."),qi(!1),te||re?qr():!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(U),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=Pe.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,y(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 Ur(e),[3,6];case 5:return o=u.sent(),l=new Map,ge.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Ur(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Ui,wi]);var Yr=(null===(B=(null===(Y=null==ge?void 0:ge.tiers)||void 0===Y?void 0:Y[0])||ie||"Tier 1")||void 0===B?void 0:B.toLowerCase().replace(/ /g,"_"))||"tier_1",Br=null!==(W=null!=Rt?Rt:ae)&&void 0!==W?W:0,Wr=null!=Rt,Kr=Wr?null==wt?void 0:wt[Br]:null,Qr=wt&&(null==wt?void 0:wt.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Bt.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)&&Bt.includes(Kr.new_variant_id)?Kr.new_variant_id:(null==Qr?void 0:Qr.new_variant_id)&&Bt.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=Pe.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])||Yr,f=dt.get(p),g=vt.get(p),m=gt.get(p),y=(null==f?void 0:f.get(o))||n.rule_description||"",w=(null==g?void 0:g.get(o))||[],h=w.length>0?w.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wta||"",b=(null==m?void 0:m.get(o))||[],I=b.length>0?b.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wnta||"",T=zn.get(p),A=null==T?void 0:T.get(o),M={};A&&Object.keys(A).length>0?M=e(e({},A),{order_rules:e(e({},A.order_rules),{global_min_separation_seconds:60*((null===(s=A.order_rules)||void 0===s?void 0:s.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},A.advertiser_rules),{global_min_separation_seconds:60*((null===(u=A.advertiser_rules)||void 0===u?void 0:u.global_min_separation_seconds)||0)})}):n.scheduling_config&&(M=n.scheduling_config),t[v]={rule_title:rt,variant_description:y,wta:h,ruleset_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:a,wnta:I,scope:i,scope_rule_set:r,scheduling_config:M,is_user_accepted_risk:!(null===(_=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(wt||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===_||!_)}}),t};Tn&&console.log("customMetaData.ui_state for addvariant flow",$r(Mt));var Xr=A(function(e){return e.selectedRuleSetId});Ye.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==Pe?void 0:Pe.length))return[];var t=A.getState().backwardCompatibility,i=tn.current,r=(wt||[])[i]||{},a=Pr(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,y,w,h,b,I,T,A=n.toLowerCase().replace(/ /g,"_"),M=(null===(a=dt.get(A))||void 0===a?void 0:a.get(i))||"",S=(null===(u=vt.get(A))||void 0===u?void 0:u.get(i))||[],k=(null===(d=gt.get(A))||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===(v=null===(_=null===(c=zn.get(A))||void 0===c?void 0:c.get(i))||void 0===_?void 0:_.is_default_enabled)||void 0===v||v,tier_id:(null===(p=Pe.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===A||e.tier_name.toLowerCase()===A.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(A,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===(w=null===(y=zn.get(A))||void 0===y?void 0:y.get(i))||void 0===w?void 0:w.is_default_enabled)||void 0===h||h,tier_id:(null===(b=Pe.find(function(e){return(null==e?void 0:e.tier_name)&&(e.tier_name.toLowerCase().replace(/ /g,"_")===A||e.tier_name.toLowerCase()===A.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(A,i,r.variant_type||r.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(I=null==dr?void 0:dr.email)&&void 0!==I?I:"",instantLearningType:j.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(T=null==r?void 0:r.is_user_accepted_risk)&&void 0!==T?T:null==Ft?void 0:Ft.is_user_accepted_risk)},isAgentsFeedback:!0})}})}(),ui_state:Zr?{variants:function(){var n={},t=zn.get(Yr);if(!t)return n;var i=dt.get(Yr),r=vt.get(Yr),a=gt.get(Yr),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=Pe.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,y=(wt||[])[d],w=(null==y?void 0:y.new_variant_id)||"",h=m||w||Jt[d]||"variant_".concat(d),b=(null==i?void 0:i.get(d))||"",I=((null==r?void 0:r.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",T=((null==a?void 0:a.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",A=t.get(d),M={};A&&Object.keys(A).length>0&&(M=e(e({},A),{order_rules:e(e({},A.order_rules),{global_min_separation_seconds:60*((null===(_=A.order_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},A.advertiser_rules),{global_min_separation_seconds:60*((null===(v=A.advertiser_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)})})),n[h]={rule_title:rt,variant_description:b,wta:I,ruleset_id:(null==ne?void 0:ne.ruleSetId)||"",tier_id:s,wnta:T,scope:o,scope_rule_set:l,scheduling_config:M,is_user_accepted_risk:!(null===(g=null!==(p=null==y?void 0:y.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=(wt||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:mn?s=-1:Tn||(s=Br),{new_current_variant:-1!==s?{rule_title:rt,rule_description:(null===(n=dt.get(Yr))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=vt.get(Yr))||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(Yr))||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(Yr))||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=(wt||[])[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?$r(Mt):{}}}(),rule_id_in_current_session:Et,new_variant_id:function(){var e;return Wr&&te?(null===(e=null==re?void 0:re[Br])||void 0===e?void 0:e.variantId)?null:zr:null}(),edit_variant_id:Rn,rule_id:jn.current,backward_compatibility:A.getState().backwardCompatibility,ruleset_id:Xr,current_variants_length:te?Array.isArray(wt)&&wt.length>0?Math.max((null===(K=null==te?void 0:te.variants)||void 0===K?void 0:K.length)||0,wt.length):null===(Q=null==te?void 0:te.variants)||void 0===Q?void 0:Q.length:void 0,tiers:A.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=vt.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=(wt||[])[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=Vr(re,n,"variantType"),console.log("Found matching variant at index",n,":",c);var _=re[n];if(_){if(!c.label){var v=_.variantType||"",p=J(v);c={label:"variant ".concat(n+1),isDefault:p}}if(_.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=Vr(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 y="variant ".concat(l+1),w=r.get(n)||"";return{variantId:Jt[n]||d.variant_id||d.variantId,variantType:y,isDefault:m,isModified:d.is_modified,tier:t,index:n,ruleDescription:w.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(w),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 yr(e,n,t)},editWhenToApply:function(e,n,t,i){return wr(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 Ir(e,n,t,i)},addNewVariant:function(e){return Tr(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=_(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:Vt,isAiStreaming:wi,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(){yn(!1)},100)},validationErrors:Oi,activeEditId:Nn,setActiveEditId:xn,pendingEditId:En,setPendingEditId:On,conflictReason:Di,usedFor:te||re?"Edit":"Create"},Yn),{scrollTrigger:ri});console.log(Rt,"editVariantIndex checking"),d(function(){},[Z]),d(function(){if(!wi&&Nt&&!!(!te&&!re)){var e=n([],wt,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||wt.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),Dt(e))}},[wi,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=vt.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,_;return void 0===o&&(o=!1),t(this,void 0,void 0,function(){var t,v,p,f,g,m,y,w,h,I,T,A,M,S,k,N,x,C,E,O,L,R,D,j;return i(this,function(i){switch(i.label){case 0:if(t=r.question_id,v=(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(jn.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",v),Dn(v),v?(-1!==(p=(wt||[]).findIndex(function(e){return e.is_new_variant}))&&(Ci(!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===v});return-1!==t&&setTimeout(function(){Dt(t),ai(function(e){return e+1}),Ti.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=Ai.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}))),yn(!1)):(console.log("lastLoadedQuestionIdRef.current in else",jn.current),null===jn.current&&(Ci(!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),Ci(!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,Vn.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(),(y=Date.now()-g)<3e3?[4,new Promise(function(e){return setTimeout(e,3e3-y)})]:[3,4];case 3:i.sent(),i.label=4;case 4:return 0===(w=(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),Ci(!1),Ki(""),null===(u=Ai.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),I=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,T="tier_1",A="Tier 1",M="1",I&&((S=String(I).match(/(\d+)/))?(k=S[1],M=k,T="tier_".concat(k),A="Tier ".concat(k)):(T=String(I).toLowerCase().trim().replace(/ /g,"_"),A=T.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),M=T.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(A," (ID: ").concat(M,", Key: ").concat(T,")")),me({station:ee||"global",tiers:[A]}),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,_=e.scheduling_config||{};l.set(n,{order_rules:{enabled:!!_.order_global_min_separation_seconds||!!(null===(t=_.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor((_.order_global_min_separation_seconds||(null===(i=_.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!_.advertiser_global_min_separation_seconds||!!(null===(r=_.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor((_.advertiser_global_min_separation_seconds||(null===(a=_.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!_.respect_inventory_code||!!(null===(o=_.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!_.respect_break_code||!!(null===(c=_.break_code_rules)||void 0===c?void 0:c.respect_break_code)},is_default_enabled:J(e.variantType||e.variant_type)}),s.set(n,q(e.rule_description||""));var v=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,v);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}}(w,h,T,M,t,v),x=N.transformedVariants,C=N.tierConfigMap,E=N.tierDescMap,O=N.tierWtaMap,L=N.tierWntaMap,Tt(function(e){var n=new Map(e);return n.set(T,JSON.parse(JSON.stringify(x))),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),x,!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),x,!0)}),An(!0),jn.current=t,Dn(v),R=0,v&&-1!==(D=x.findIndex(function(e){return e.variant_id===v}))&&(R=D),Dt(R),ai(function(e){return e+1}),Ti.current=R,yn(!1),Zn(function(e){var n=new Map(e);return n.set(T,C),n}),ct(function(e){var n=new Map(e);return n.set(T,E),n}),pt(function(e){var n=new Map(e);return n.set(T,O),n}),mt(function(e){var n=new Map(e);return n.set(T,L),n}),Li({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(_=Ai.current)||void 0===_||_.show({severity:"error",summary:"Error",detail:"Failed to fetch variants. Please try again.",life:3e3}),[3,10];case 6:return Mn.current=!1,Ci(!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}),Ti.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),Ci(!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(),Ci(!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}),Ti.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}),Ti.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),Ti.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return Un.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:Ai}),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(P,{}),customSections:a(o,{}),customMetaData:Ye,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:Ce,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,qr()]:[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(U),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=Pe.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,y(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,Ur(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)}),Ur(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:Cr,aiResponse:wt,setAIResponse:ht,width:"90vw",height:"90vh",sendMessageInChat:Pt,template:k.CreateRule,isLoading:we===U,templateProps:{state:na,handlers:ta,uiState:oa},setSendMessageInChat:Vt,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(vt.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!=ve?ve:Hn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(we===G||Ie)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=vt.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 _=null==o?void 0:o.get(d);if(!(null==_?void 0:_.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})})})})(vt)&&!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:wi,setIsAiStreaming:hi,showConfirmReset:Si,setShowConfirmReset:ki,confirmReset:function(){kr(),ki(!1),la()},isLoadingVariants:xi,mainText:Wi,subText:zi,proposedRule:an,isFetchingComparison:fr,handleOpenComparison:xr,showComparison:Hi,setShowComparison:Yi,variants:sn,onComparisonLinkClick:pr,targetComparisonVariantId:cn,highlightedComparisonField:pn,onAddAsVariant:function(){Yi(!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,I(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?_e:"",socketTimeOutInMilliSeconds:Hn.SOCKET_TIMEOUT})]})};export{Y as default,q as filterAgentText};
|
|
2
2
|
//# sourceMappingURL=InstantLearningModal.js.map
|