@e-llm-studio/instant-learning 0.1.1-alpha.18 → 0.1.1-alpha.19
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/RuleContent/RuleContent.js +1 -1
- package/dist/cjs/features/LearningManagement/apis/apiConfig.js +1 -1
- package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/cjs/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +1 -1
- package/dist/features/LearningManagement/RuleContent/RuleContent.js +1 -1
- package/dist/features/LearningManagement/apis/apiConfig.js +1 -1
- package/dist/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +1 -1
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts +1 -1
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/InstantLearningModal.d.ts +3 -0
- package/dist/types/src/features/LearningManagement/components/InstantLearningModal.d.ts.map +1 -1
- package/dist/types/src/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.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 M from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as A}from"../store/useLearningTemplateStore.js";import I from"../styles/InstantLearningModal.module.css.js";import S from"../../IL-OTJ/ILOTJ.js";import"../../IL-OTJ/_components/atoms/Textarea/Textarea.js";import"../../IL-OTJ/_components/InputDataReasoningCard.js";import"../../IL-OTJ/_components/TooltipComponent.js";import{TemplateList as k}from"../../IL-OTJ/_components/templates/TemplatesMap/templatesMap.js";import{extractAndParseWithProperty as C,parseValidationData as N,extractAndParseResponse as E,extractVariantIds as x}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"./ToolTip.js";import L from"../store/useAuthStore.js";import"date-fns";import"framer-motion";import"@mui/icons-material/Close";import{useConfigStore as R}from"../store/useConfigStore.js";import"@radix-ui/react-tooltip";import"./StationOnboarding/InputField.js";import"../store/useEnvStore.js";var D=function(){return a("img",{src:M,alt:"Thinking...",width:"20",height:"20"})},j="INITIAL",V="SUCCESS",P="FAILURE",F="IN_PROGRESS",G=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},q=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},U=function(M){var U,J,H,B,W,K,Y=M.isOpen,z=M.onClose,Q=M.initialScope,Z=void 0===Q?"global":Q,$=M.ruleSet,X=M.editingRule,ee=M.editingTier,ne=M.editingVariants,te=M.focusedVariantIndex,ie=M.setFocusedVariantIndex,re=M.triggerAddVariant,ae=M.triggerFixGaps,oe=M.copiedRule,le=M.copiedSourceTier,se=M.copiedTargetTier,ue=M.initialDraftMessage,de=s({station:Z,tiers:["Tier 1"]}),ce=de[0],ve=de[1],_e=s(j),pe=_e[0],fe=_e[1],ge=s(!1),me=ge[0],we=ge[1],ye=s("Thank you teacher for teaching me, your rule has been saved successfully."),he=ye[0];ye[1];var be=s(""),Te=be[0],Me=be[1],Ae=s(!1),Ie=Ae[0],Se=Ae[1],ke=u(null),Ce=s(!1),Ne=Ce[0],Ee=Ce[1],xe=u(!1),Oe=A().tiers,Le=l.useRef(new Set),Re=s(null);Re[0];var De=Re[1],je=s(null);je[0];var Ve=je[1],Pe=s(null);Pe[0];var Fe=Pe[1],Ge=u(new Map),qe=u(""),Ue=u(!1),Je=s(0),He=Je[0],Be=Je[1],We=s(!1),Ke=We[0],Ye=We[1],ze=u(null),Qe=u(0),Ze=s(null),$e=Ze[0],Xe=Ze[1],en=s([]),nn=en[0],tn=en[1],rn=s(null),an=rn[0],on=rn[1],ln=s(null),sn=ln[0],un=ln[1],dn=s(!1),cn=dn[0],vn=dn[1],_n=u({}),pn=u([]),fn=u(!1),gn=s(!1),mn=gn[0],wn=gn[1],yn=u(!1),hn=u(new Set),bn=s(null),Tn=bn[0],Mn=bn[1],An=s(null),In=An[0],Sn=An[1],kn=s(null),Cn=kn[0],Nn=kn[1],En=u(null),xn=u(null),On=u(null),Ln=u({}),Rn=u([]),Dn=u([]),jn=u({}),Vn=R(),Pn=Vn.configuration,Fn=Vn.ilLabels;d(function(){Tn||Sn(null)},[Tn]),d(function(){var e;if(Y&&X){En.current=X.ruleId;var n=null===(e=null==ne?void 0:ne[te||0])||void 0===e?void 0:e.variantId;Nn(n||null)}},[Y,X,ne,te]),d(function(){Y&&ve(function(n){return e(e({},n),{station:Z})})},[Y,Z]),d(function(){console.log("triggered",Cn),console.log(ct,"structuredAIResponse"),vt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Cn&&n.new_variant_id!==Cn})}):n}),wt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Cn&&n.new_variant_id!==Cn})}):n})},[Cn]),d(function(){var n;if(!Y)return yr(),void(fn.current=!1);if(!fn.current){var t=ne,i=t&&t.length>0,r=null!=X;if(i||r){if((null==X?void 0:X.ruleTitle)&&Zn(X.ruleTitle),ee&&(ve(function(n){return e(e({},n),{tiers:[ee]})}),xn.current=ee.toLowerCase().replace(/ /g,"_")),i){var a=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"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[te||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==X?void 0:X.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==X?void 0:X.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"}});vt(p),vt(p),wt(p),ft(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:q(e.variantType||e.variant_type)})}),Jn(new Map([[a,f]])),it(o),ot(l),ut(s)}else if(r&&X){var g=X.ruleDesc;if(g&&it(new Map([["tier_1",new Map([[0,g]])]])),X.whenToApply){var m=X.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:""}});ot(new Map([["tier_1",new Map([[0,m]])]]))}if(X.whenNotToApply){var w=X.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:""}});ut(new Map([["tier_1",new Map([[0,w]])]]))}}}else if(oe&&le&&se){Zn(oe.ruleTitle||""),ve(function(n){return e(e({},n),{tiers:[se]})}),xn.current=se.toLowerCase().replace(/ /g,"_");var y=le.toLowerCase().replace(/ /g,"_"),h=oe.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),T=new Map,M=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:""}}):[];M.set(n,i)}),o.set(y,b),l.set(y,T),s.set(y,M),it(o),ot(l),ut(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:oe.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[le],scheduling_config:r||{},variant_id:e.variantId,question_id:oe.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"}});vt(A),wt(A),ft(function(e){var n=new Map(e);return n.set(y,JSON.parse(JSON.stringify(A))),n});var I=new Map;h.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,f=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,g=null!==(a=null!==(i=null==f?void 0:f.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==f?void 0:f.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,m=null!==(s=null!==(o=null==f?void 0:f.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==f?void 0:f.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;I.set(n,{order_rules:{enabled:g>0,global_min_separation_seconds:Math.floor(g/60)},advertiser_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==f?void 0:f.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==f?void 0:f.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==f?void 0:f.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:q(e.variantType||e.variant_type)})}),Jn(new Map([[y,I]]))}}},[Y,X,ne,ee,oe,le,se]),d(function(){if(Y){if(console.log("[Accordion Init] editingTier:",ee,"focusedVariantIndex:",te),ee&&ve(function(n){return e(e({},n),{tiers:[ee]})}),cn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void kt(void 0);if(re){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),kt(void 0);var n=((null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_1").replace(/_/g," ");Et("I want to add a new variant to ".concat(n))}else null!=te?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(te," (from VariantCard)")),kt(te),Zt(function(e){return e+1})):(X||ne&&ne.length>0)&&(console.log("[Accordion] Opening DEFAULT/1st variant (index 0) for RuleHeader edit"),kt(0),Zt(function(e){return e+1}))}else kt(void 0)},[Y,ee,te,X,ne,re,cn]),d(function(){Y&&ae&&X&&null!==te&&Et("I want to fix the gaps")},[Y,ae,X,te]);var Gn={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,Gn]])],["tier_2",new Map([[0,Gn]])]])),Un=qn[0],Jn=qn[1],Hn=s(new Set([])),Bn=Hn[0],Wn=Hn[1],Kn=s("");Kn[0];var Yn=Kn[1],zn=s(""),Qn=zn[0],Zn=zn[1],$n=s(new Map([["tier_1",new Map],["tier_2",new Map]])),Xn=$n[0],et=$n[1],nt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),tt=nt[0],it=nt[1],rt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),at=rt[0],ot=rt[1],lt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),st=lt[0],ut=lt[1],dt=s([]),ct=dt[0],vt=dt[1],_t=s(new Map),pt=_t[0],ft=_t[1],gt=s([]),mt=gt[0],wt=gt[1],yt=s(!1),ht=yt[0],bt=yt[1],Tt=s([]),Mt=Tt[0],At=Tt[1],It=s(void 0),St=It[0],kt=It[1],Ct=s(""),Nt=Ct[0],Et=Ct[1],xt=s(null),Ot=xt[0],Lt=xt[1],Rt=s([]),Dt=Rt[0],jt=Rt[1],Vt=s([]),Pt=Vt[0],Ft=Vt[1],Gt=s({}),qt=Gt[0],Ut=Gt[1],Jt=s(new Map),Ht=Jt[0],Bt=Jt[1],Wt=s(new Set),Kt=Wt[0],Yt=Wt[1],zt=s(0),Qt=zt[0],Zt=zt[1],$t=s({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Xt=$t[0],ei=$t[1],ni=s([]),ti=ni[0],ii=ni[1],ri=s(""),ai=ri[0],oi=ri[1],li=s({}),si=li[0],ui=li[1],di=s(!1),ci=di[0],vi=di[1],_i=u(null),pi=u(null),fi=u(-1),gi=u(null);d(function(){Dn.current=ct},[ct]),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=gi.current)||void 0===i||i.show({severity:"warn",sticky:!1,life:5e3,className:I.toastWarning,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconWarning}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleWarning)},{children:"Parsing Issue"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageWarning)},{children:"The AI response couldn't be parsed correctly. Please try rephrasing your input or retry."}))]}))})}},function(){console.warn=t}},[]);var mi=s(!1),wi=mi[0],yi=mi[1],hi=s(!1),bi=hi[0],Ti=hi[1],Mi=s({}),Ai=Mi[0],Ii=Mi[1],Si=s(""),ki=Si[0],Ci=Si[1],Ni=s(!0),Ei=Ni[0],xi=Ni[1],Oi=s(!1),Li=Oi[0],Ri=Oi[1],Di=s(!1),ji=Di[0],Vi=Di[1],Pi=s(""),Fi=Pi[0],Gi=Pi[1],qi=s(""),Ui=qi[0],Ji=qi[1],Hi=s(""),Bi=Hi[0],Wi=Hi[1],Ki=s(null),Yi=Ki[0],zi=Ki[1],Qi=s(null),Zi=Qi[0],$i=Qi[1],Xi=s(null),er=Xi[0],nr=Xi[1],tr=L.getState().user,ir=O(),rr=ir.dispatch,ar=ir.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",ct)},[ct]),d(function(){console.log("isCloseModal AI Response updated:",Ei)},[Ei]),d(function(){!1===ci?(Ti(!1),Gi(""),Ji("")):(Se(!1),Me(""))},[ci]),d(function(){null!=St&&ne&&!ne[St]&&zi(null)},[St,ne]),d(function(){if(Ne&&!xe.current){xe.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");Et("Save this Learning"),Ee(!1),setTimeout(function(){xe.current=!1,Et("")},2e3)}},[Ne]);var or=c(function(e,n){nn.some(function(n){return n.id===e})?(Vi(!0),on(e),un(n),setTimeout(function(){un(null),on(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[nn]),lr=v(function(){var e=ji&&He>0;return console.log("[Loader Debug] showComparison: ".concat(ji,", activeRequests: ").concat(He,", Result: ").concat(e)),e},[ji,He]),sr=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;it(function(e){var i=new Map(e),r=new Map(i.get(n));return r.set(t,a),i.set(n,r),i}),Ii(function(i){if(i["ruleDescription-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["ruleDescription-".concat(n,"-").concat(t)],r}return i})},[]),ur=c(function(t,i){ot(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}),Ii(function(n){if(n["whenToApply-".concat(t,"-").concat(i)]){var r=e({},n);return delete r["whenToApply-".concat(t,"-").concat(i)],r}return n})},[]),dr=c(function(e,n,t){ot(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})},[]),cr=c(function(n,t,i,r){ot(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}),Ii(function(i){if(i["whenToApply-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["whenToApply-".concat(n,"-").concat(t)],r}return i})},[]),vr=c(function(e,t){ut(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})},[]),_r=c(function(e,n,t){ut(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})},[]),pr=c(function(n,t,i,r){ut(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})},[]),fr=c(function(e){var n=e.replace(/_/g," ");vn(!0),null==ie||ie(null),kt(void 0),Et("I want to add a new variant to ".concat(n))},[]),gr=function(n,t,i){var r="".concat(n,"_").concat(t);console.log("Highlighting ".concat(i," at ").concat(r)),Bt(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(){Bt(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){ve(function(i){var r;return e(e({},i),((r={})[n]=t,r))}),Ii(function(t){if(t[n]){var i=e({},t);return delete i[n],i}return t})},[]),wr=c(function(n,t,i,r){et(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}),Jn(function(a){var o,l,s,u=new Map(a),d=new Map(u.get(n)||new Map),c=d.get(t)||Gn;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(){ci&&(Vi(!1),un(null),on(null))},[ci]);var yr=c(function(n){var t;if(void 0===n&&(n=!1),n||(rr({type:"RESET"}),_i.current=null,vt([]),At([]),ii([]),ui({}),Vi(!1),Le.current.clear()),Zn(""),jt([]),vn(!1),qe.current="",Wi(""),$i(null),Ft([]),ve({station:"",tiers:[]}),Be(0),Ye(!1),nr(null),it(new Map([["tier_1",new Map],["tier_2",new Map]])),ot(new Map([["tier_1",new Map],["tier_2",new Map]])),ut(new Map([["tier_1",new Map],["tier_2",new Map]])),Jn(new Map([["tier_1",new Map([[0,Gn]])],["tier_2",new Map([[0,Gn]])]])),et(new Map([["tier_1",new Map],["tier_2",new Map]])),Yn(""),kt(0),Zt(0),ve({station:Z,tiers:["Tier 1"]}),n||Ut({}),et(new Map([["tier_1",new Map],["tier_2",new Map]])),Et(""),ei({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Ii({}),Ci(""),xi(!0),De(null),Ve(null),ft(new Map),wt([]),wn(!1),Fe(null),pi.current=null,Ue.current=!1,_n.current={},hn.current.clear(),En.current=null,xn.current=null,Nn(null),Me(""),fe(j),we(!1),Se(!1),Ee(!1),Xe(null),tn([]),on(null),un(null),Mn(null),bt(!1),Lt(null),Gi(""),Ji(""),Ti(!1),Wn(new Set),xe.current=!1,Ge.current.clear(),Qe.current=0,ze.current=null,On.current=null,fi.current=-1,yn.current=!1,fn.current=!1,X){X.ruleTitle&&Zn(X.ruleTitle),ee&&(ve(function(n){return e(e({},n),{tiers:[ee]})}),xn.current=ee.toLowerCase().replace(/ /g,"_")),En.current=X.ruleId;var i=null===(t=null==ne?void 0:ne[te||0])||void 0===t?void 0:t.variantId;if(Nn(i||null),ne&&ne.length>0){var r=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;ne.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),it(a),ot(o),ut(l);var c=ne.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:X.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:X.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"}});vt(c),wt(c),ft(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var v=new Map;ne.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:q(e.variantType||e.variant_type)})}),Jn(new Map([[r,v]])),kt(null!=te?te:0)}}},[rr,Z,X,ee,ne,te]),hr=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)},br=c(function(){console.log("variantIds",Dt),Vi(!0)},[Dt]),Tr={"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;fi.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),kt(r),fi.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=C(t),a=C(t,"general_details");console.log("--- [CARE] Staging Initial Structure ---",r);var o=C(t,"critical_gaps");if(console.log("isCriticalGap",o),Ye(!!o),r){if(r.variant_type&&!("is_variant"in r)){var l=null===(i=Ar(r.variant_type||"").toLowerCase().match(/^(default_variant|default|variant)/i))||void 0===i?void 0:i[0];r.variant_type=q(l)?"Default":"variant",r.isDefault=q(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?Ar(s).toLowerCase().trim().replace(/ /g,"_"):null,d=Boolean(u&&xn.current!==u);if(d&&u){var c=xn.current;console.log("[Tier Switch Detected]",xn.current,"→",u),xn.current=u,En.current=null;var v=(Dn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===v&&void 0!==St&&(v=St),c&&-1!==v&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(v," from ").concat(c)),it(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),ot(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),ut(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),Jn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),vt(function(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_","")})),Dn.current=i,i})),fi.current=-1;var _=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});ve(function(n){return e(e({},n),{tiers:[_]})})}Lt(r),De({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)&&na(a,r,d),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&En.current&&Cn?vt(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===Cn?e(e({},n),r):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===Cn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),kt(i),Zt(function(e){return e+1}),fi.current=i},0),t}):(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&En.current&&!Cn?vt(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(){kt(a),Zt(function(e){return e+1}),fi.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(){kt(o),Zt(function(e){return e+1}),fi.current=o},0),i=n(n([],t,!0),[e(e({},r),{is_new_variant:!0})],!1)}}else setTimeout(function(){kt(0),Zt(function(e){return e+1}),fi.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return Dn.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(vt([r]),setTimeout(function(){kt(0),Zt(function(e){return e+1}),fi.current=0},0)),void 0!==r.is_user_accepted_risk&&vt(function(t){var i=!(!X&&!ne),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&ne&&ne.length>0&&(a=ne.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==X?void 0:X.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",is_valid:!0,is_readOnly:e.variantId!==Cn,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=Yi||Zi,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!==St&&(l=St),-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=N(t)}if(Ve(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){Lt(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(ct)){var r=Yi||Zi,a=-1;!(!X&&!ne)&&r&&(a=ct.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!==St&&(a=St),-1!==a&&(i=ct[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=(ee||"Tier 1").toLowerCase().replace(/ /g,"_"),s=function(){var e,n=Dn.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(Cn)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Cn||(null==e?void 0:e.new_variant_id)===Cn})))return t;if(Yi)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Yi||(null==e?void 0:e.new_variant_id)===Yi})))return t;var r=null!==(e=null==ne?void 0:ne.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!==St?St: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&&(Ii(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}),Ci("")),o.conflict_view&&((null===(r=o.conflict_view.wta)||void 0===r?void 0:r.length)>0&&ot(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&&ut(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&&(Ii({}),Ci(""),ot(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}),ut(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=E(e);(console.log("parsedaction",n),"load"===(null==n?void 0:n.action)&&(null==n?void 0:n.question_id)&&na(n,null),"save"===(null==n?void 0:n.action)&&(null==n?void 0:n.is_save)&&(xi(!0),Ri(!0)),"discard_rule"===(null==n?void 0:n.action))&&(vt([{variant_id:void 0,rule_description:"",wta:"",wnta:"",variant_type:"variant"}]),wt([]),Nn(null),kt(0),Zt(0),Mn(null),wn(!1),vn(!1),jt([]),En.current=null,Zn(""),nr(null),Jn(new Map([["tier_1",new Map([[0,Gn]])],["tier_2",new Map([[0,Gn]])]])),it(new Map([["tier_1",new Map],["tier_2",new Map]])),ot(new Map([["tier_1",new Map],["tier_2",new Map]])),ut(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),on(l))}catch(e){console.error("Failed to parse rule_validation_card JSON",e)}}var s=C(t,"critical_gaps");console.log("isCriticalGap",s),Ye(!!s);var u="string"==typeof t?E(t):t;console.log("parsed data from Validation Agent",u);var d=x(t);Fe(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);xi(v),Ri(_);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&&zi(u.edit_variant_id),"edit"!==p&&"edit_current_rule"!==p||!f||$i(f),g&&(zi(null),$i(null)),"discard"===p)return console.log("Action 'discard' received: Resetting UI state but preserving chat."),fn.current=!0,yr(!0),vt([]),_i.current=null,void(pi.current=null);Wi(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)&&!ne;(null==u?void 0:u.is_valid)?(Ii({}),Lt(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(ct)&&h&&(y=h,ct.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)||!X&&!ne)return w;console.log("inside edit flow merge");var b=ne||[],T=f,M=T?b.findIndex(function(e){return e.variantId===T||e.variant_id&&e.variant_id===T||e.id&&e.id===T}):-1;if(-1===M&&(null==u?void 0:u.set_variant_id)&&(M=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===M&&T&&Array.isArray(ct)&&(M=ct.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!==M){var A,I,S,k=b[M]||(null==ct?void 0:ct[M]),C=(null==k?void 0:k.tier_id)||(null==k?void 0:k.tierId)||"1",N=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_".concat(C);if(fi.current!==M&&(kt(M),fi.current=M),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)?I=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)?I=null!==(v=null==u?void 0:u.wnta)&&void 0!==v?v:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(I=null!==(_=null==t?void 0:t.wnta)&&void 0!==_?_:""),void 0!==A){var E=Ar(A);Ir(N,M,A,E,at,ot,null==u?void 0:u.conflict_view),gr(N,M,"wta")}if(void 0!==I){var x=Ar(I);Ir(N,M,I,x,st,ut,null==u?void 0:u.conflict_view),gr(N,M,"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=Ar(S);it(function(e){var n=new Map(e),t=new Map(n.get(N)||new Map);return t.set(M,O),n.set(N,t),n}),gr(N,M,"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&&(Jn(function(e){var n,i,r,a,o,l,s=new Map(e),u=new Map(s.get(N)||new Map);return u.set(M,{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(N,u),s}),gr(N,M,"order_enabled"),gr(N,M,"advertiser_enabled"),gr(N,M,"respect_inventory_code"),gr(N,M,"respect_break_code")),vt(function(t){if(!Array.isArray(t)||M<0||!t[M])return t;var i=n([],t,!0),r=e({},i[M]);return void 0!==A&&(r.wta=A),void 0!==I&&(r.wnta=I),void 0!==S&&(r.rule_description=Ar(S)),L&&(r.scheduling_config=L),console.log("updated variantxxx",r),i[M]=r,i});var R=null==t?void 0:t.variant_type;R&&vt(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[M]=e(e({},i[M]||{}),{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?(bt(!0),m&&m!==pi.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),Ti(!0),Gi("Loading a variant"),console.log("reaching here in new variant flow"),Ji("This may take a moment as we update the rule with the new variant."),pi.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(bt(!1),pi.current=null),d&&jt(d))},"Rule comparison results":function(e){try{var n=e;if("string"==typeof e)try{n=JSON.parse(e)}catch(t){n=E(e)||[]}if(!Array.isArray(n)){if(!n||"object"!=typeof n)return void console.error("[Rule comparison results] Data is not an array:",e);n=[n]}var t=n.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}});tn(t)}catch(e){console.error("[Rule comparison results] Critical Handler Error:",e)}}},Mr=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},Ar=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},Ir=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)||"",_=Mr(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&&(Yt(function(e){return new Set(n(n([],Array.from(e),!0),g,!0))}),setTimeout(function(){Yt(function(e){var n=new Set(e);return g.forEach(function(e){return n.delete(e)}),n})},1500))}}},Sr=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(){Nt&&!xe.current&&"save this learning"!==Nt.toLowerCase()&&(Se(!1),Me(""),fi.current=null!=St?St:-1)},[Nt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Rn.current=ti,Array.isArray(ct)&&ct.length>0){var c=ai||"local-".concat(Date.now()),v=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],_={},p=_i.current||[];ct.forEach(function(t,i){var r,a;if(t){t.is_readOnly||(Qe.current=i);var o=i;if((null==t?void 0:t.variant_id)&&ne)-1!==(l=ne.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if(Yi&&ne&&1===ct.length){var l;-1!==(l=ne.findIndex(function(e){return e.variantId===Yi}))&&(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=Sr(u).map(function(e){return e.toLowerCase().replace(/ /g,"_")}),c=d.length>0?d:pn.current.length>0?pn.current:["tier_1"];c.length>0&&(pn.current=c),console.log("prevTierRef.current",pn.current,"targetTiers",c);var f=Ar(t.title);f&&f!==Ar(null==s?void 0:s.title)&&!t.is_readOnly&&function(e,n,t,i,r,a){var o=Ar(i);o&&o!==r&&(gr(e,n,t),a(o))}("global",0,"ruleTitle",t.title,Qn,Zn),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=Ar(t.rule_description),w=(null===(l=tt.get(r))||void 0===l?void 0:l.get(o))||"",y=Ar(w);g&&(m!==y||""===m&&""!==w)&&(it(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}),gr(r,o,"ruleDescription"));var h=!1===(null==Ot?void 0:Ot.is_valid),b=Ar(t.wta),T=Ar(null==c?void 0:c.wta),M=(null===(s=at.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&M.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==T||""===b&&M.length>0||0===M.length&&""!==b)&&(Ir(r,o,t.wta,b,at,ot,null==Ot?void 0:Ot.conflict_view),gr(r,o,"wta"));var A=Ar(t.wnta),I=Ar(null==c?void 0:c.wnta),S=(null===(u=st.get(r))||void 0===u?void 0:u.get(o))||[];if(!(h&&""===A&&S.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(A!==I||""===A&&S.length>0||0===S.length&&""!==A)&&(Ir(r,o,t.wnta,A,st,ut,null==Ot?void 0:Ot.conflict_view),gr(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}},C=null==c?void 0:c.scheduling_config,N=null===(d=Un.get(r))||void 0===d?void 0:d.get(o),E=t.variant_type||t.variantType,x=E?q(E):void 0,O=JSON.stringify(k)!==JSON.stringify(C),L=void 0!==x&&x!==(null==N?void 0:N.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(Ut(function(e){return R(e,k)}),O||L){Ut(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,Un);D.forEach(function(e){return gr(r,o,e)}),Wn(function(e){return new Set(e).add("config")}),Jn(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)||Gn;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!==x&&{is_default_enabled:x})),d.set(r,c),d}),et(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!==x&&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=Mr(j[e]),t="ruleTitle"===e||"scopeData"===e?e:"".concat(e,"_").concat(r);n&&(n!==Ln.current[t]&&(Ln.current[t]=n,jn.current[t]=!0,_[t]={reasoning:n,associatedCitations:[],tier:r,variantIndex:o}))}),t.conflictingConditions&&(Ii(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}),Wn(function(e){return new Set(n(n([],Array.from(e),!0),["conditions"],!1))}))})}});var f=-1,g=!(!X&&!ne),m="edit"===Bi||"edit_current_rule"===Bi,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(pi.current&&ht)-1!==(f=ct.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===pi.current||(null==e?void 0:e.variant_id)&&e.variant_id===pi.current||(null==e?void 0:e.id)&&e.id===pi.current}))&&(pi.current=null);else if(Yi||Zi){var h;(h=Yi||Zi)&&(f=y(ct,h))}else if(re&&Array.isArray(ct)&&ct.length>0){for(b=ct.length-1;b>=0;b--)if(ct[b]&&!(null===(i=ct[b])||void 0===i?void 0:i.is_readOnly)){f=b;break}}else null==te||_i.current&&0!==_i.current.length||(f=te);else if((h=Yi||Zi||pi.current)&&m&&(f=y(ct,h)),!m&&-1===f&&Array.isArray(ct)&&ct.length>0){for(var b=ct.length-1;b>=0;b--)if(ct[b]&&!(null===(t=ct[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=ct.length-1)}-1!==f&&St!==f&&(fi.current===f||Ue.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),kt(f),fi.current=f));var T=ct[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=Sr(l),d=s?Sr(s):[],ve(function(n){return e(e({},n),{tiers:u})}),u.forEach(function(e){var n=e.trim();d.includes(e)||gr("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 M=T.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(M)&&(ve(function(n){return e(e({},n),{station:M})}),gr("global",0,"scope_station"))}T.wtl&&Yn(T.wtl)}_i.current=ct.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&&(rr({type:"SAVE_CITATIONS",requestId:c,reasoningMap:_,rawCitations:ti}),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:ar,currentCitations:ti}),ei(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}))}},[ct,ti,ai]),d(function(){var t=Object.keys(jn.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],ti,!0)}),jn.current={},ui(function(n){return e(e({},n),i)})}},[ti]);var kr=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==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==Pn?void 0:Pn.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==$?void 0:$.ruleSetDesc)||""}}})},Cr=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(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"];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:{respect_break_code:"bool",respect_inventory_code:"bool",order_global_min_separation_seconds:"int",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",advertiser_global_min_separation_seconds:"int",advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",advertiser_exemption_priority_code_list:"array",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",break_code_exemption_priority_code_list:"array",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",inventory_exemption_priority_code_list:"array",override_priority_code:"str",custom_sep_time_for_entities:"object"}},config_data:{scheduling_config:n}}},Nr=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},Er=function(e,n,t){void 0===t&&(t="variantType");var i=null==e?void 0:e[n];if(!i)return{label:hr(e),isDefault:!1};var r=i[t]||"",a=q(r);return{label:"variant ".concat(n+1),isDefault:a}},xr=function(e,n){var t=q(e);return{label:"variant ".concat(n+1),isDefault:t}},Or=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=Un.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":q(t)?"Default":"Variant"},Lr=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,M,S,k;return i(this,function(i){switch(i.label){case 0:t=kr(ce.tiers),l=Qe.current,s=Nr(Xn,qt,Un,l),i.label=1;case 1:return i.trys.push([1,3,,4]),fe(F),Me(""),u=Cr(s),d=m(),c=[],v=[],p=(ct||[])[l]||{},console.log("originalItem check :",p,l),ce.tiers.forEach(function(i){var r,a,o,s,_,f,g,w,h,b,T,M=i.toLowerCase().replace(/ /g,"_");v.push(M);var A=(null===(r=tt.get(M))||void 0===r?void 0:r.get(l))||"",I=(null===(a=at.get(M))||void 0===a?void 0:a.get(l))||[],S=(null===(o=st.get(M))||void 0===o?void 0:o.get(l))||[],k={status:"approved",metadata:e(e({userName:null!==(s=null==tr?void 0:tr.firstname)&&void 0!==s?s:"",userEmailId:null!==(_=null==tr?void 0:tr.email)&&void 0!==_?_:"",llm:Pn.MODEL,isVariantFlow:!0},u&&{config:e({master_name:Pn.CONFIG_MASTER_NAME},u)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d,variant:Ar(A),conditions_whentoapply:I.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:S.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:t[0]||{name:Pn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,description:(null==$?void 0:$.ruleSetDesc)||""}},overriden:!1,isDefault:null===(w=null===(g=null===(f=Un.get(M))||void 0===f?void 0:f.get(l))||void 0===g?void 0:g.is_default_enabled)||void 0===w||w,tier:{name:i.split(" ").join("").toLowerCase(),tierGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(h=Oe.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===M||e.tier_name.toLowerCase()===M.replace(/_/g,"")}))||void 0===h?void 0:h.tier_id)||""},topic:{id:null,value:"".concat(ce.station||Z,"RuleSet"),description:null},categories:[{id:null,value:Pn.CATEGORY,description:Pn.CATEGORY}],originalQuestion:Qn,questionId:n.get(M)||null,variantType:Or(M,l,p.variant_type||p.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==tr?void 0:tr.email)&&void 0!==b?b:"",instantLearningType:Pn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(T=null==p?void 0:p.is_user_accepted_risk)&&void 0!==T?T:null==Ot?void 0:Ot.is_user_accepted_risk)},isAgentsFeedback:!0})};c.push(y(k,Pn.ASSISTANT_NAME))}),[4,Promise.all(c)];case 2:return g=i.sent(),Ee(!1),console.log("✅ All feedback published:",g),fe(V),we(!0),w=new Map,g.forEach(function(e,n){var t,i,r=v[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=w.get(r)||[];o.push({id:a,action:"new"}),w.set(r,o)}}),A.getState().setCreatedVariantInfo(Array.from(w.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(M=gi.current)||void 0===M||M.show({severity:"success",sticky:!1,life:6e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),ke.current=setTimeout(function(){Ei||o?(console.log("Closing modal after save success",{isCloseModal:Ei,forceClose:o}),Xr()):yr(!0)},3e3),[3,4];case 3:return h=i.sent(),console.error("❌ Error publishing feedback:",h),Ee(!1),fe(P),Se(!0),b=(null===(S=null==h?void 0:h.response)||void 0===S?void 0:S.data)||{},console.log("errorData: ",b),(T="Variant already exists"===(null==b?void 0:b.message))||409===(null==h?void 0:h.status)?Me('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>'):Me(((null==b?void 0:b.message)||(null==b?void 0:b.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(k=gi.current)||void 0===k||k.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:T||409===(null==h?void 0:h.status)?"Similar rule already exists. Please update and try again.":(null==b?void 0:b.message)||(null==b?void 0:b.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Rr=function(){return t(void 0,void 0,void 0,function(){var t,o,l,s,u,d,c,v,p,g,w,b,T,M,S,k,C,N,E,x,O,L,R,D,j,U;return i(this,function(i){switch(i.label){case 0:t=A.getState().tiers,o=Nr(Xn,qt,Un),l=Cr(o),s=Qe.current,u=(ct||[])[s]||{},d=(null==Ot?void 0:Ot.variant_type)||u.variant_type||"",i.label=1;case 1:for(i.trys.push([1,3,,4]),fe(F),Me(""),v=(c=ne||[]).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=ce.tiers[0])||void 0===L?void 0:L.toLowerCase().replace(/ /g,"_"))||"tier_1",g=(null===(R=tt.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=[],M=[],S=kr(ce.tiers),ce.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=tt.get(i),o=at.get(i),s=st.get(i);w.forEach(function(t,c){var _,p,f,g,w,b,A,I,k,C,N,E,x,O,L,R,D,j,V,P,F,U,J,H,B,W,K,Y,z=(null==a?void 0:a.get(c))||t.description||"",Q=(null==o?void 0:o.get(c))||[],Z=(null==s?void 0:s.get(c))||[];if(t.isNewVariant){M.push({tierKey:i,payloadType:"new"});var ee=Nr(Xn,qt,Un,c),ne=Cr(ee);console.log("variant in save edit add part :",t,u);var te={status:"approved",metadata:e(e({userName:null!==(_=null==tr?void 0:tr.firstname)&&void 0!==_?_:"",userEmailId:null!==(p=null==tr?void 0:tr.email)&&void 0!==p?p:"",llm:Pn.MODEL,isVariantFlow:!0},ne&&{config:e({master_name:Pn.CONFIG_MASTER_NAME},ne)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:v||m(),variant:Ar(z),conditions_whentoapply:Q.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:Pn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,description:(null==$?void 0:$.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=Un.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:q(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(ce.station,"RuleSet"),description:null},categories:[{id:null,value:Pn.CATEGORY,description:Pn.CATEGORY}],originalQuestion:Qn,questionId:null==X?void 0:X.ruleId,variantType:Or(i,c,u.variant_type||""),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==tr?void 0:tr.email)&&void 0!==b?b:"",instantLearningType:Pn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(I=null===(A=(ct||[])[c])||void 0===A?void 0:A.is_user_accepted_risk)&&void 0!==I?I:null==Ot?void 0:Ot.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",te),T.push(y(te,Pn.ASSISTANT_NAME))}else{M.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var ie=t.variantId===Yi,re=Or(i,c,ie?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",re,ie,t,Yi);var ae={variantId:t.variantId,ruleDesc:(null==$?void 0:$.ruleSetDesc)||"",whenToApply:Q.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!==(N=null===(C=null===(k=Un.get(i))||void 0===k?void 0:k.get(c))||void 0===C?void 0:C.is_default_enabled)&&void 0!==N?N:q(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!==(E=null==r?void 0:r.tier_priority)&&void 0!==E?E:null},scope_id:(null==$?void 0:$.ruleSetId)||"",description:Ar(z)||"",topic:"".concat(ce.station,"RuleSet"),configuration:(null==l?void 0:l.config_data)||{},tierLinkId:null!=v?v:null,variantType:re,is_user_accepted_risk:!!(null!==(O=null===(x=(ct||[])[c])||void 0===x?void 0:x.is_user_accepted_risk)&&void 0!==O?O:null==t?void 0:t.is_user_accepted_risk),is_enabled:t.is_enabled},oe=(pt.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=G(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ue=se(Qn)===se(oe.title),de=se(z)===se(oe.rule_description),ve=se(ae.whenToApply)===se(oe.wta),_e=se(ae.whenNotToApply)===se(oe.wnta),pe=!!ae.isDefault===q(oe.variant_type),fe=oe.scheduling_config||{},ge=null!==(D=null!==(L=fe.order_global_min_separation_seconds)&&void 0!==L?L:null===(R=fe.order_rules)||void 0===R?void 0:R.global_min_separation_seconds)&&void 0!==D?D:0,me=null!==(P=null!==(j=fe.advertiser_global_min_separation_seconds)&&void 0!==j?j:null===(V=fe.advertiser_rules)||void 0===V?void 0:V.global_min_separation_seconds)&&void 0!==P?P:0,we=null!==(J=null!==(U=null===(F=fe.inventory_rules)||void 0===F?void 0:F.respect_inventory_code)&&void 0!==U?U:fe.respect_inventory_code)&&void 0!==J&&J,ye=null!==(W=null!==(B=null===(H=fe.break_code_rules)||void 0===H?void 0:H.respect_break_code)&&void 0!==B?B:fe.respect_break_code)&&void 0!==W&&W,he=(null===(K=Un.get(i))||void 0===K?void 0:K.get(c))||Gn,be=he.order_rules.enabled===ge>0&&he.order_rules.global_min_separation_seconds===Math.floor(ge/60)&&he.advertiser_rules.enabled===me>0&&he.advertiser_rules.global_min_separation_seconds===Math.floor(me/60)&&he.inventory_rules.respect_inventory_code===we&&he.break_code_rules.respect_break_code===ye;ue&&de&&ve&&_e&&pe&&be&&(le=!1)}le?(console.log("payloadv (update existing variant)",ae),T.push(h(ae,null!==(Y=null==tr?void 0:tr.email)&&void 0!==Y?Y:""))):(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),fe(V),we(!0),Ee(!1),C=new Map,k.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=M[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=C.get(r.tierKey)||[];l.push({id:o,action:r.payloadType}),C.set(r.tierKey,l)}}}),A.getState().setCreatedVariantInfo(Array.from(C.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=gi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),ke.current=setTimeout(function(){Xr()},3e3),[3,4];case 3:return N=i.sent(),console.error("❌ Error updating variant:",N),fe(P),Se(!0),Ee(!1),E=(null===(j=null==N?void 0:N.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",E),(x="Variant already exists"===(null==E?void 0:E.message))||409===(null==N?void 0:N.status)?Me('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>'):Me(((null==E?void 0:E.message)||(null==E?void 0:E.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(U=gi.current)||void 0===U||U.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:x||409===(null==N?void 0:N.status)?"Similar rule already exists. Please update and try again.":(null==E?void 0:E.message)||(null==E?void 0:E.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Dr=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,M,S,k,C,N,E,x,O,L,R,D,j,U;return i(this,function(i){switch(i.label){case 0:n=A.getState().tiers,t=Nr(Xn,qt,Un),o=Cr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),fe(F),Me(""),0===(l=Array.isArray(ct)?ct:[]).length?(console.warn("No variants found to save."),fe(P),[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=kr(ce.tiers),ce.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=tt.get(i),s=at.get(i),u=st.get(i);l.forEach(function(n,l){var _,f,y,b,T,M,A,I,S,k,C,N,E,x,O,L,R,D,j,V,P,F,U,J,H,B,W,K=(null==a?void 0:a.get(l))||n.rule_description||n.description||"",Y=(null==s?void 0:s.get(l))||[],z=(null==u?void 0:u.get(l))||[];if(n.is_new_variant){var Q=Nr(Xn,qt,Un,l),X=Cr(Q),ee=Or(i,l,n.variant_type||n.variantType||""),ne={status:"approved",metadata:e(e({userName:null!==(_=null==tr?void 0:tr.firstname)&&void 0!==_?_:"",userEmailId:null!==(f=null==tr?void 0:tr.email)&&void 0!==f?f:"",llm:Pn.MODEL,isVariantFlow:!0},X&&{config:e({master_name:Pn.CONFIG_MASTER_NAME},X)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Ar(K),conditions_whentoapply:Y.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:w[0]||{name:Pn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,description:(null==$?void 0:$.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(T=null===(b=null===(y=Un.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==T?T:q(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:Pn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(t.split(" ")[1]||"1"),tier_id:(null==r?void 0:r.tier_id)||""},topic:{id:null,value:"".concat(ce.station||Z,"RuleSet"),description:null},categories:[{id:null,value:Pn.CATEGORY,description:Pn.CATEGORY}],originalQuestion:Qn,questionId:En.current||null,variantType:ee,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(M=null==tr?void 0:tr.email)&&void 0!==M?M:"",instantLearningType:Pn.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==Ot?void 0:Ot.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ne),v.push({payload:ne,tierKey:i}),g.push({tierKey:i})}else if(null==n?void 0:n.variant_id){p.push({tierKey:i,existingId:n.variant_id});var te=(null==n?void 0:n.variant_id)&&n.variant_id===er?(null==Ot?void 0:Ot.variant_type)||n.variant_type||n.variantType||"":n.variant_type||n.variantType||"",ie=(ee=Or(i,l,te),{variantId:n.variant_id,ruleDesc:(null==$?void 0:$.ruleSetDesc)||"",whenToApply:Y.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!==(k=null===(S=null===(I=Un.get(i))||void 0===I?void 0:I.get(l))||void 0===S?void 0:S.is_default_enabled)&&void 0!==k?k:q(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!==(C=null==r?void 0:r.tier_priority)&&void 0!==C?C:null},scope_id:(null==$?void 0:$.ruleSetId)||"",description:Ar(K)||"",topic:"".concat(ce.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:ee,is_user_accepted_risk:!!(null!==(N=null==n?void 0:n.is_user_accepted_risk)&&void 0!==N?N:null===(E=(ct||[])[l])||void 0===E?void 0:E.is_user_accepted_risk),is_enabled:n.is_enabled}),re=(pt.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=G(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},le=oe(Qn)===oe(re.title),se=oe(K)===oe(re.rule_description),ue=oe(ie.whenToApply)===oe(re.wta),de=oe(ie.whenNotToApply)===oe(re.wnta),ve=!!ie.isDefault===q(re.variant_type),_e=re.scheduling_config||{},pe=null!==(L=null!==(x=_e.order_global_min_separation_seconds)&&void 0!==x?x:null===(O=_e.order_rules)||void 0===O?void 0:O.global_min_separation_seconds)&&void 0!==L?L:0,fe=null!==(j=null!==(R=_e.advertiser_global_min_separation_seconds)&&void 0!==R?R:null===(D=_e.advertiser_rules)||void 0===D?void 0:D.global_min_separation_seconds)&&void 0!==j?j:0,ge=null!==(F=null!==(P=null===(V=_e.inventory_rules)||void 0===V?void 0:V.respect_inventory_code)&&void 0!==P?P:_e.respect_inventory_code)&&void 0!==F&&F,me=null!==(H=null!==(J=null===(U=_e.break_code_rules)||void 0===U?void 0:U.respect_break_code)&&void 0!==J?J:_e.respect_break_code)&&void 0!==H&&H,we=(null===(B=Un.get(i))||void 0===B?void 0:B.get(l))||Gn,ye=we.order_rules.enabled===pe>0&&we.order_rules.global_min_separation_seconds===Math.floor(pe/60)&&we.advertiser_rules.enabled===fe>0&&we.advertiser_rules.global_min_separation_seconds===Math.floor(fe/60)&&we.inventory_rules.respect_inventory_code===ge&&we.break_code_rules.respect_break_code===me;le&&se&&ue&&de&&ve&&ye&&(ae=!1)}ae?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ie),c.push(h(ie,null!==(W=null==tr?void 0:tr.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=[],M=0,S=v,i.label=3;case 3:if(!(M<S.length))return[3,8];k=S[M],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(k.payload,Pn.ASSISTANT_NAME)];case 5:return C=i.sent(),T.push(C),[3,7];case 6:throw N=i.sent(),console.error("❌ Error publishing new variant:",N),N;case 7:return M++,[3,3];case 8:return console.log("✅ All new variants published:",T),E=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=E.get(r.tierKey)||[];l.push({id:o,action:"existing"}),E.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=E.get(r.tierKey)||[];o.push({id:a,action:"new"}),E.set(r.tierKey,o)}}),A.getState().setCreatedVariantInfo(Array.from(E.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),fe(V),we(!0),Ee(!1),Ue.current=!1,null===(D=gi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),ke.current=setTimeout(function(){Xr()},3e3),[3,10];case 9:return x=i.sent(),console.error("❌ Error updating variant:",x),fe(P),Se(!0),Ee(!1),O=(null===(j=null==x?void 0:x.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",O),(L="Variant already exists"===(null==O?void 0:O.message))||409===(null==x?void 0:x.status)?Me('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>'):Me(((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===(U=gi.current)||void 0===U||U.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:L||409===(null==x?void 0:x.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]}})})},jr=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(){Li&&!ci&&(console.log("isSaveRule received from agent — calling publish APIs directly."),Ri(!1),X||ne?Rr():!0===Ue.current?Dr():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]),fe(F),e=new Map,n=function(n){var t,r,a,o,l,u;return i(this,function(i){switch(i.label){case 0:if(t=n.toLowerCase().replace(/ /g,"_"),r=Oe.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:Qn,orgName:Pn.ORGANIZATION_NAME,scope_id:(null==$?void 0:$.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=ce.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 Lr(e),[3,6];case 5:return o=u.sent(),l=new Map,ce.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Lr(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Li,ci]);var Vr=(null===(J=(null===(U=null==ce?void 0:ce.tiers)||void 0===U?void 0:U[0])||ee||"Tier 1")||void 0===J?void 0:J.toLowerCase().replace(/ /g,"_"))||"tier_1",Pr=null!==(H=null!=St?St:te)&&void 0!==H?H:0,Fr=null!=St,Gr=Fr?null==ct?void 0:ct[Pr]:null,qr=ct&&(null==ct?void 0:ct.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Pt.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&Dt.includes(e.variant_id))})),Ur=(null==Gr?void 0:Gr.new_variant_id)&&Pt.includes(Gr.new_variant_id)?Gr.new_variant_id:(null==qr?void 0:qr.new_variant_id)&&Pt.includes(qr.new_variant_id)?qr.new_variant_id:"",Jr=!(!X&&!ne),Hr=function(n){var t={},i=ce.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),r=(null==ce?void 0:ce.station)+"RuleSet",a=i.map(function(e){var n=Oe.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||Dt[o]||"new_variant_".concat(o),p=(null===(l=n.scope)||void 0===l?void 0:l[0])||Vr,f=tt.get(p),g=at.get(p),m=st.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||"",M=Un.get(p),A=null==M?void 0:M.get(o),I={};A&&Object.keys(A).length>0?I=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&&(I=n.scheduling_config),t[_]={rule_title:Qn,variant_description:w,wta:h,ruleset_id:(null==$?void 0:$.ruleSetId)||"",tier_id:a,wnta:T,scope:i,scope_rule_set:r,scheduling_config:I,is_user_accepted_risk:!(null===(v=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(ct||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===v||!v)}}),t};mn&&console.log("customMetaData.ui_state for addvariant flow",Hr(mt));var Br={send_metadata_to_orchestrator:!1,default:["scope"],ui_state:Jr?{variants:function(){var n={},t=Un.get(Vr);if(!t)return n;var i=tt.get(Vr),r=at.get(Vr),a=st.get(Vr),o=ce.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),l=(null==ce?void 0:ce.station)+"RuleSet",s=o.map(function(e){var n=Oe.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==ne?void 0:ne[d])||void 0===c?void 0:c.variantId,w=(ct||[])[d],y=(null==w?void 0:w.new_variant_id)||"",h=m||y||Dt[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 ")||"",M=((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),I={};A&&Object.keys(A).length>0&&(I=e(e({},A),{order_rules:e(e({},A.order_rules),{global_min_separation_seconds:60*((null===(v=A.order_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},A.advertiser_rules),{global_min_separation_seconds:60*((null===(_=A.advertiser_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)})})),n[h]={rule_title:Qn,variant_description:b,wta:T,ruleset_id:(null==$?void 0:$.ruleSetId)||"",tier_id:s,wnta:M,scope:o,scope_rule_set:l,scheduling_config:I,is_user_accepted_risk:!(null===(g=null!==(p=null==w?void 0:w.is_user_accepted_risk)&&void 0!==p?p:null===(f=null==ne?void 0:ne[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=(ct||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:cn?s=-1:mn||(s=Pr),{new_current_variant:-1!==s?{rule_title:Qn,rule_description:(null===(n=tt.get(Vr))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=at.get(Vr))||void 0===t?void 0:t.get(s))||void 0===i?void 0:i.map(function(e){return jr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",wnta:(null===(a=null===(r=st.get(Vr))||void 0===r?void 0:r.get(s))||void 0===a?void 0:a.map(function(e){return jr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",scope:ce.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),scope_rule_set:(null==ce?void 0:ce.station)+"RuleSet",scheduling_config:function(){var n,t,i,r=null===(n=Un.get(Vr))||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=(ct||[])[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:mn?Hr(mt):{}}}(),rule_id_in_current_session:Mt,new_variant_id:function(){var e;return Fr&&X?(null===(e=null==ne?void 0:ne[Pr])||void 0===e?void 0:e.variantId)?null:Ur:null}(),edit_variant_id:Cn,rule_id:En.current,ruleset_id:(null==$?void 0:$.ruleSetId)||"",current_variants_length:X?Array.isArray(ct)&&ct.length>0?Math.max((null===(B=null==X?void 0:X.variants)||void 0===B?void 0:B.length)||0,ct.length):null===(W=null==X?void 0:X.variants)||void 0===W?void 0:W.length:void 0,tiers:Oe,authToken:(null==tr?void 0:tr.accessToken)||""},Wr=hr(mt),Kr={ruleTitle:Qn,scopeData:ce,variantsByTier:Array.from(Un.keys()).reduce(function(n,t){var i=Un.get(t)||new Map,r=tt.get(t)||new Map,a=at.get(t)||new Map,o=st.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=(ct||[])[n]||{};console.log("Original item for tier",t,"index",n,":",d);var c={label:"",isDefault:!1};if(d.is_variant&&!q(d.variant_type))c={label:"",isDefault:!1};else if(ne&&ne.length>0){c=Er(ne,n,"variantType"),console.log("Found matching variant at index",n,":",c);var v=ne[n];if(v){if(!c.label){var _=v.variantType||"",p=q(_);c={label:"variant ".concat(n+1),isDefault:p}}if(v.variantId===Yi)(g=d.variant_type||(null==Ot?void 0:Ot.variant_type))&&(c=xr(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:hr(ne),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(mt&&mt.length>0){if(c=Er(mt,n,"variant_type"),console.log("Found matching variant at index",n,":",c),Ue.current){var f=mt[n];if((null==f?void 0:f.variant_id)===er||(null==f?void 0:f.variantId)===er)(g=d.variant_type||(null==Ot?void 0:Ot.variant_type))&&(c=xr(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:Wr,isDefault:q(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:Dt[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)||Gn,isReadOnly:d.is_readOnly||!1,is_variant:d.is_variant||!1,reasoning:{ruleDescription:Mr(y),whenToApply:Mr(d.wta),whenNotToApply:Mr(d.wnta),configData:Mr(d.action)}}}),n},{}),citation:Xt,fieldCitations:si,citations:ti};console.log("templateState",Kr);var Yr={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;Zn(i),Ii(function(n){if(n.ruleTitle){var t=e({},n);return delete t.ruleTitle,t}return n})},setRuleDescription:function(e,n,t){return sr(e,n,t)},addWhenToApply:function(e,n){return ur(e,n)},removeWhenToApply:function(e,n,t){return dr(e,n,t)},editWhenToApply:function(e,n,t,i){return cr(e,n,t,i)},addWhenNotToApply:function(e,n){return vr(e,n)},removeWhenNotToApply:function(e,n,t){return _r(e,n,t)},editWhenNotToApply:function(e,n,t,i){return pr(e,n,t,i)},addNewVariant:function(e){return fr(e)},onScopeChange:mr,onConfigChange:function(e,n,t,i){return wr(e,n,t,i)}},zr={},Qr={};Un.forEach(function(n,t){zr[t]=new Map,Qr[t]=new Map,n.forEach(function(n,i){zr[t].set(i,[e({key:"order_rules",label:"Order"},n.order_rules),e({key:"advertiser_rules",label:"Advertiser"},n.advertiser_rules)]),Qr[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 Zr=v(function(){if(ee){if(1===ce.tiers.length)return 0;var e=ce.tiers.findIndex(function(e){return e.toLowerCase()===ee.toLowerCase()});return e>=0?e:0}},[ee,ce.tiers]),$r=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:zr,togglesByTier:Qr,highlights:Ht,highlightedIds:Kt,openSections:Bn,setOpenSections:Wn,setSendMessageInChat:Et,isAiStreaming:ci,defaultTierOpen:Zr,defaultVariantOpen:cn?void 0:St,autoScrollVariantIndex:cn?void 0:St,activeVariantAccordionIndex:cn?void 0:St,setActiveVariantAccordionIndex:function(e){kt(e),null!=e&&setTimeout(function(){vn(!1)},100)},validationErrors:Ai,activeEditId:Tn,setActiveEditId:Mn,pendingEditId:In,setPendingEditId:Sn,conflictReason:ki,usedFor:X||ne?"Edit":"Create"},Fn),{scrollTrigger:Qt});console.log(St,"editVariantIndex checking"),d(function(){},[Y]),d(function(){if(!ci&&ht&&!!(!X&&!ne)){var e=n([],ct,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||ct.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),kt(e))}},[ci,ht]);var Xr=function(){ke.current&&(clearTimeout(ke.current),ke.current=null),Ue.current=!1,z(),yr()},ea=function(){var e={};Qn.trim()||(e.ruleTitle="Rule Title is required"),ce.station||(e.station="Station Rule Set is required"),ce.tiers&&0!==ce.tiers.length||(e.tiers="At least one tier must be selected");return ce.tiers.map(function(e){return e.toLowerCase().replace(/ /g,"_")}).forEach(function(n){var t=tt.get(n),i=at.get(n),r=Un.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 na(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,M,A,I,S,k,C,N,E,x,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,yn.current&&On.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(En.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",_),Nn(_),_?(-1!==(p=(ct||[]).findIndex(function(e){return e.is_new_variant}))&&(Ti(!0),Gi("Removing new variant..."),Ji("Please wait while we remove new variant.")),vt(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(){kt(t),Zt(function(e){return e+1}),fi.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})})(Jn),f(it),f(ot),f(ut),jt(function(e){var t=n([],e,!0);return t.length>p&&t.splice(p,1),t})),!1===yn.current&&(yn.current=!0,-1!==p&&(null===(l=gi.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}))),vn(!1)):(console.log("lastLoadedQuestionIdRef.current in else",En.current),null===En.current&&(Ti(!0),Gi("Adding new variant..."),Ji("Please wait while we add new variant."))),[2];console.log("User Action: fetching fresh variant info for question",t),hn.current.clear(),hn.current.add(t),Ti(!0),Gi("Loading variants..."),console.log("reaching here in load and edit"),Ji("Please wait while we fetch the latest variant data."),yn.current=!0,On.current=t,i.label=1;case 1:return i.trys.push([1,5,6,10]),g=Date.now(),[4,b(t,(null==$?void 0:$.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),Ti(!1),Gi(""),null===(u=gi.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(Ue.current=!0,yn.current=!0,h=(null===(d=null==m?void 0:m.data)||void 0===d?void 0:d.ruleTitle)||"",Zn(h),T=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,M="tier_1",A="Tier 1",I="1",T&&((S=String(T).match(/(\d+)/))?(k=S[1],I=k,M="tier_".concat(k),A="Tier ".concat(k)):(M=String(T).toLowerCase().trim().replace(/ /g,"_"),A=M.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),I=M.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(A," (ID: ").concat(I,", Key: ").concat(M,")")),ve({station:Z||"global",tiers:[A]}),C=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:q(e.variantType||e.variant_type)}),s.set(n,G(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,M,I,t,_),N=C.transformedVariants,E=C.tierConfigMap,x=C.tierDescMap,O=C.tierWtaMap,L=C.tierWntaMap,ft(function(e){var n=new Map(e);return n.set(M,JSON.parse(JSON.stringify(N))),n}),vt(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),N,!0)}),wt(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),N,!0)}),wn(!0),En.current=t,Nn(_),R=0,_&&-1!==(D=N.findIndex(function(e){return e.variant_id===_}))&&(R=D),kt(R),Zt(function(e){return e+1}),fi.current=R,vn(!1),Jn(function(e){var n=new Map(e);return n.set(M,E),n}),it(function(e){var n=new Map(e);return n.set(M,x),n}),ot(function(e){var n=new Map(e);return n.set(M,O),n}),ut(function(e){var n=new Map(e);return n.set(M,L),n}),Ii({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(v=gi.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 yn.current=!1,Ti(!1),Gi(""),Ji(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&En.current&&Cn?(console.log("inside edit variant flow",En.current,Cn),vt(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)===Cn?e(e({},n),a):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Cn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),kt(i),Zt(function(e){return e+1}),fi.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)&&En.current&&!Cn?(console.log("inside add new variant flow",En.current,Cn),Ti(!0),Gi("Adding new variant..."),Ji("Please wait while we add new variant."),[4,new Promise(function(e){return setTimeout(e,3e3)})]):[3,9];case 8:i.sent(),Ti(!1),Gi(""),Ji(""),vt(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(){kt(r),Zt(function(e){return e+1}),fi.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(){kt(o),Zt(function(e){return e+1}),fi.current=o},0),i=n(n([],t,!0),[e(e({},a),{is_new_variant:!0,is_variant:!0})],!1)}}else setTimeout(function(){kt(0),Zt(0),fi.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return Dn.current=i,i}),i.label=9;case 9:return[7];case 10:return[2]}})})}var ta;return console.log("RuleSet in render",$),r(o,{children:[a(g,{ref:gi}),a(S,{open:Y,chatAssistantName:Pn.ASSISTANT_NAME,organizationName:Pn.ORGANIZATION_NAME,baseUrl:Pn.BASE_URL,baseWebsocketUrl:Pn.BASE_WEBSOCKET_URL,closeFunction:Xr,ThinkingBulbIconComponent:a(D,{}),customSections:a(o,{}),customMetaData:Br,chatTitle:X?Pn.CHAT_TITLE_EDIT.replace("<scope>",(null==$?void 0:$.ruleSetName)||""):Pn.CHAT_TITLE.replace("<scope>",(null==$?void 0:$.ruleSetName)||""),formTitle:Pn.FORM_TITLE,showSavedMessage:!1,savedMessage:he,isError:Ie,errorMessage:Te,isSaving:Ne,onSave:function(e){console.log("Save this Learning",e);var n=ea();if(Object.keys(n).length>0)return console.log("validation errors",n),void Ii(n);Ee(!0),Se(!1),Me("")},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=ea(),Object.keys(e).length>0?(Ii(e),[2]):(console.log("✅ Bypass Save: Initiated"),X||ne?[4,Rr()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==Ue.current?[3,4]:[4,Dr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),fe(F),n=new Map,t=function(e){var t,r,a,o,l,s;return i(this,function(i){switch(i.label){case 0:if(t=e.toLowerCase().replace(/ /g,"_"),r=Oe.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:Qn,orgName:Pn.ORGANIZATION_NAME,scope_id:(null==$?void 0:$.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=ce.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,Lr(n,!0)];case 9:return d.sent(),[3,11];case 10:return l=d.sent(),fe(P),s=new Map,ce.tiers.forEach(function(e){s.set(e.toLowerCase().replace(/ /g,"_"),null)}),Lr(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:Tr,aiResponse:ct,setAIResponse:vt,width:"90vw",height:"90vh",sendMessageInChat:Nt,template:k.CreateRule,isLoading:pe===F,templateProps:{state:Kr,handlers:Yr,uiState:$r},setSendMessageInChat:Et,onResetChat:function(){yr()},onResetRequest:function(){yi(!0)},isFormDirty:function(){return""!==Qn.trim()||""!==ce.station||ce.tiers.length>0||Array.from(tt.values()).some(function(e){return Array.from(e.values()).some(function(e){return""!==e.trim()})})||Array.from(at.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Array.from(st.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Un.size>0||Xn.size>0},initialChatMessage:X?(ta=X.ruleTitle||"this rule",null===(K=null==ne?void 0:ne[null!=te?te:0])||void 0===K||K.is_user_accepted_risk,'<p><span>Welcome back! 👋</span>\n <span>I see you want to edit <strong>"'.concat(ta,'."</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>')):Pn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(pe===V||me)return!1;if(!Qn||""===Qn.trim())return!1;if(null!==Tn)return!1;if(!ce.station||""===ce.station.trim())return!1;var e=ce.tiers&&ce.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=tt.get(r),o=at.get(r),l=Un.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!(!Un||0===Un.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})})})})(at)&&!n(st)&&!Ke)},setCitations:ii,isLocked:!0,textareaPlaceholder:"Tell me more about this learning..",saveButtonConfig:{label:X?"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:oi,isAiStreaming:ci,setIsAiStreaming:vi,showConfirmReset:wi,setShowConfirmReset:yi,confirmReset:function(){yr(),yi(!1),Xr()},isLoadingVariants:bi,mainText:Fi,subText:Ui,proposedRule:$e,isFetchingComparison:lr,handleOpenComparison:br,showComparison:ji,setShowComparison:Vi,variants:nn,onComparisonLinkClick:or,targetComparisonVariantId:an,highlightedComparisonField:sn,onAddAsVariant:function(){Vi(!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==tr?void 0:tr._id)&&void 0!==a?a:"",user_name:null!==(o=null==tr?void 0:tr.firstname)&&void 0!==o?o:"",user_email:null!==(l=null==tr?void 0:tr.email)&&void 0!==l?l:"",assistant_name:Pn.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!==Tn&&(e.target.closest('[data-edit-id="'.concat(Tn,'"]'))||(e.preventDefault(),e.stopPropagation(),Sn(Tn)))},isGlobalEditActive:null!==Tn,initialDraftMessage:oe?ue:"",socketTimeOutInMilliSeconds:Pn.SOCKET_TIMEOUT})]})};export{U as default,G as filterAgentText};
|
|
1
|
+
import{__assign as e,__spreadArray as n,__awaiter as t,__generator as i}from"tslib";import{jsxs as r,jsx as a,Fragment as o}from"react/jsx-runtime";import l,{useState as s,useRef as u,useEffect as d,useCallback as c,useMemo as v}from"react";import{AlertTriangle as _,Loader as p,Check as f}from"lucide-react";import{Toast as g}from"primereact/toast";import{v4 as m}from"uuid";import{saveInstantLearningQuestion as w,publishFeedback as y,updateVariant as h,fetchRulesByQuestionId as b,submitChatFeedback as T}from"../apis/scopeApis.js";import M from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as A}from"../store/useLearningTemplateStore.js";import I from"../styles/InstantLearningModal.module.css.js";import k 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 S}from"../../IL-OTJ/_components/templates/TemplatesMap/templatesMap.js";import{extractAndParseWithProperty as C,parseValidationData as N,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"./ToolTip.js";import L from"../store/useAuthStore.js";import"date-fns";import"framer-motion";import"@mui/icons-material/Close";import{useConfigStore as R}from"../store/useConfigStore.js";import"@radix-ui/react-tooltip";import"./StationOnboarding/InputField.js";import"../store/useEnvStore.js";var D=function(){return a("img",{src:M,alt:"Thinking...",width:"20",height:"20"})},j="INITIAL",V="SUCCESS",P="FAILURE",q="IN_PROGRESS",F=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},G=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},J=function(M){var J,U,H,B,W,K,Y=M.isOpen,z=M.onClose,Q=M.initialScope,Z=void 0===Q?"global":Q,$=M.ruleSet,X=M.editingRule,ee=M.editingTier,ne=M.editingVariants,te=M.focusedVariantIndex,ie=M.setFocusedVariantIndex,re=M.triggerAddVariant,ae=M.triggerFixGaps,oe=M.copiedRule,le=M.copiedSourceTier,se=M.copiedTargetTier,ue=M.initialDraftMessage,de=M.initialChatMessage;M.applicationIntegrationId,M.modeId;var ce=s({station:Z,tiers:["Tier 1"]}),ve=ce[0],_e=ce[1],pe=s(j),fe=pe[0],ge=pe[1],me=s(!1),we=me[0],ye=me[1],he=s("Thank you teacher for teaching me, your rule has been saved successfully."),be=he[0];he[1];var Te=s(""),Me=Te[0],Ae=Te[1],Ie=s(!1),ke=Ie[0],Se=Ie[1],Ce=u(null),Ne=s(!1),xe=Ne[0],Ee=Ne[1],Oe=u(!1),Le=A().tiers,Re=l.useRef(new Set),De=s(null);De[0];var je=De[1],Ve=s(null);Ve[0];var Pe=Ve[1],qe=s(null);qe[0];var Fe=qe[1],Ge=u(new Map),Je=u(""),Ue=u(!1),He=s(0),Be=He[0],We=He[1],Ke=s(!1),Ye=Ke[0],ze=Ke[1],Qe=u(null),Ze=u(0),$e=s(null),Xe=$e[0],en=$e[1],nn=s([]),tn=nn[0],rn=nn[1],an=s(null),on=an[0],ln=an[1],sn=s(null),un=sn[0],dn=sn[1],cn=s(!1),vn=cn[0],_n=cn[1],pn=u({}),fn=u([]),gn=u(!1),mn=s(!1),wn=mn[0],yn=mn[1],hn=u(!1),bn=u(new Set),Tn=s(null),Mn=Tn[0],An=Tn[1],In=s(null),kn=In[0],Sn=In[1],Cn=s(null),Nn=Cn[0],xn=Cn[1],En=u(null),On=u(null),Ln=u(null),Rn=u({}),Dn=u([]),jn=u([]),Vn=u({}),Pn=R(),qn=Pn.configuration,Fn=Pn.ilLabels;d(function(){Mn||Sn(null)},[Mn]),d(function(){var e;if(Y&&X){En.current=X.ruleId;var n=null===(e=null==ne?void 0:ne[te||0])||void 0===e?void 0:e.variantId;xn(n||null)}},[Y,X,ne,te]),d(function(){Y&&_e(function(n){return e(e({},n),{station:Z})})},[Y,Z]),d(function(){console.log("triggered",Nn),console.log(vt,"structuredAIResponse"),_t(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Nn&&n.new_variant_id!==Nn})}):n}),yt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==Nn&&n.new_variant_id!==Nn})}):n})},[Nn]),d(function(){var n;if(!Y)return hr(),void(gn.current=!1);if(!gn.current){var t=ne,i=t&&t.length>0,r=null!=X;if(i||r){if((null==X?void 0:X.ruleTitle)&&$n(X.ruleTitle),ee&&(_e(function(n){return e(e({},n),{tiers:[ee]})}),On.current=ee.toLowerCase().replace(/ /g,"_")),i){var a=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"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[te||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==X?void 0:X.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==X?void 0:X.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"}});_t(p),_t(p),yt(p),gt(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:G(e.variantType||e.variant_type)})}),Hn(new Map([[a,f]])),rt(o),lt(l),dt(s)}else if(r&&X){var g=X.ruleDesc;if(g&&rt(new Map([["tier_1",new Map([[0,g]])]])),X.whenToApply){var m=X.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:""}});lt(new Map([["tier_1",new Map([[0,m]])]]))}if(X.whenNotToApply){var w=X.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:""}});dt(new Map([["tier_1",new Map([[0,w]])]]))}}}else if(oe&&le&&se){$n(oe.ruleTitle||""),_e(function(n){return e(e({},n),{tiers:[se]})}),On.current=se.toLowerCase().replace(/ /g,"_");var y=le.toLowerCase().replace(/ /g,"_"),h=oe.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),T=new Map,M=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:""}}):[];M.set(n,i)}),o.set(y,b),l.set(y,T),s.set(y,M),rt(o),lt(l),dt(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:oe.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[le],scheduling_config:r||{},variant_id:e.variantId,question_id:oe.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"}});_t(A),yt(A),gt(function(e){var n=new Map(e);return n.set(y,JSON.parse(JSON.stringify(A))),n});var I=new Map;h.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,_,p,f=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,g=null!==(a=null!==(i=null==f?void 0:f.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==f?void 0:f.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,m=null!==(s=null!==(o=null==f?void 0:f.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==f?void 0:f.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;I.set(n,{order_rules:{enabled:g>0,global_min_separation_seconds:Math.floor(g/60)},advertiser_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==f?void 0:f.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==f?void 0:f.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(_=null===(v=null==f?void 0:f.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==_?_:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:G(e.variantType||e.variant_type)})}),Hn(new Map([[y,I]]))}}},[Y,X,ne,ee,oe,le,se]),d(function(){if(Y){if(console.log("[Accordion Init] editingTier:",ee,"focusedVariantIndex:",te),ee&&_e(function(n){return e(e({},n),{tiers:[ee]})}),vn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void Ct(void 0);if(re){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),Ct(void 0);var n=((null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_1").replace(/_/g," ");Et("I want to add a new variant to ".concat(n))}else null!=te?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(te," (from VariantCard)")),Ct(te),$t(function(e){return e+1})):(X||ne&&ne.length>0)&&(console.log("[Accordion] Opening DEFAULT/1st variant (index 0) for RuleHeader edit"),Ct(0),$t(function(e){return e+1}))}else Ct(void 0)},[Y,ee,te,X,ne,re,vn]),d(function(){Y&&ae&&X&&null!==te&&Et("I want to fix the gaps")},[Y,ae,X,te]);var Gn={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},Jn=s(new Map([["tier_1",new Map([[0,Gn]])],["tier_2",new Map([[0,Gn]])]])),Un=Jn[0],Hn=Jn[1],Bn=s(new Set([])),Wn=Bn[0],Kn=Bn[1],Yn=s("");Yn[0];var zn=Yn[1],Qn=s(""),Zn=Qn[0],$n=Qn[1],Xn=s(new Map([["tier_1",new Map],["tier_2",new Map]])),et=Xn[0],nt=Xn[1],tt=s(new Map([["tier_1",new Map],["tier_2",new Map]])),it=tt[0],rt=tt[1],at=s(new Map([["tier_1",new Map],["tier_2",new Map]])),ot=at[0],lt=at[1],st=s(new Map([["tier_1",new Map],["tier_2",new Map]])),ut=st[0],dt=st[1],ct=s([]),vt=ct[0],_t=ct[1],pt=s(new Map),ft=pt[0],gt=pt[1],mt=s([]),wt=mt[0],yt=mt[1],ht=s(!1),bt=ht[0],Tt=ht[1],Mt=s([]),At=Mt[0],It=Mt[1],kt=s(void 0),St=kt[0],Ct=kt[1],Nt=s(""),xt=Nt[0],Et=Nt[1],Ot=s(null),Lt=Ot[0],Rt=Ot[1],Dt=s([]),jt=Dt[0],Vt=Dt[1],Pt=s([]),qt=Pt[0],Ft=Pt[1],Gt=s({}),Jt=Gt[0],Ut=Gt[1],Ht=s(new Map),Bt=Ht[0],Wt=Ht[1],Kt=s(new Set),Yt=Kt[0],zt=Kt[1],Qt=s(0),Zt=Qt[0],$t=Qt[1],Xt=s({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),ei=Xt[0],ni=Xt[1],ti=s([]),ii=ti[0],ri=ti[1],ai=s(""),oi=ai[0],li=ai[1],si=s({}),ui=si[0],di=si[1],ci=s(!1),vi=ci[0],_i=ci[1],pi=u(null),fi=u(null),gi=u(-1),mi=u(null);d(function(){jn.current=vt},[vt]),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=mi.current)||void 0===i||i.show({severity:"warn",sticky:!1,life:5e3,className:I.toastWarning,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconWarning}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleWarning)},{children:"Parsing Issue"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageWarning)},{children:"The AI response couldn't be parsed correctly. Please try rephrasing your input or retry."}))]}))})}},function(){console.warn=t}},[]);var wi=s(!1),yi=wi[0],hi=wi[1],bi=s(!1),Ti=bi[0],Mi=bi[1],Ai=s({}),Ii=Ai[0],ki=Ai[1],Si=s(""),Ci=Si[0],Ni=Si[1],xi=s(!0),Ei=xi[0],Oi=xi[1],Li=s(!1),Ri=Li[0],Di=Li[1],ji=s(!1),Vi=ji[0],Pi=ji[1],qi=s(""),Fi=qi[0],Gi=qi[1],Ji=s(""),Ui=Ji[0],Hi=Ji[1],Bi=s(""),Wi=Bi[0],Ki=Bi[1],Yi=s(null),zi=Yi[0],Qi=Yi[1],Zi=s(null),$i=Zi[0],Xi=Zi[1],er=s(null),nr=er[0],tr=er[1],ir=L.getState().user,rr=O(),ar=rr.dispatch,or=rr.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",vt)},[vt]),d(function(){console.log("isCloseModal AI Response updated:",Ei)},[Ei]),d(function(){!1===vi?(Mi(!1),Gi(""),Hi("")):(Se(!1),Ae(""))},[vi]),d(function(){null!=St&&ne&&!ne[St]&&Qi(null)},[St,ne]),d(function(){if(xe&&!Oe.current){Oe.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");Et("Save this Learning"),Ee(!1),setTimeout(function(){Oe.current=!1,Et("")},2e3)}},[xe]);var lr=c(function(e,n){tn.some(function(n){return n.id===e})?(Pi(!0),ln(e),dn(n),setTimeout(function(){dn(null),ln(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[tn]),sr=v(function(){var e=Vi&&Be>0;return console.log("[Loader Debug] showComparison: ".concat(Vi,", activeRequests: ").concat(Be,", Result: ").concat(e)),e},[Vi,Be]),ur=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;rt(function(e){var i=new Map(e),r=new Map(i.get(n));return r.set(t,a),i.set(n,r),i}),ki(function(i){if(i["ruleDescription-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["ruleDescription-".concat(n,"-").concat(t)],r}return i})},[]),dr=c(function(t,i){lt(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}),ki(function(n){if(n["whenToApply-".concat(t,"-").concat(i)]){var r=e({},n);return delete r["whenToApply-".concat(t,"-").concat(i)],r}return n})},[]),cr=c(function(e,n,t){lt(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})},[]),vr=c(function(n,t,i,r){lt(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}),ki(function(i){if(i["whenToApply-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["whenToApply-".concat(n,"-").concat(t)],r}return i})},[]),_r=c(function(e,t){dt(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})},[]),pr=c(function(e,n,t){dt(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})},[]),fr=c(function(n,t,i,r){dt(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})},[]),gr=c(function(e){var n=e.replace(/_/g," ");_n(!0),null==ie||ie(null),Ct(void 0),Et("I want to add a new variant to ".concat(n))},[]),mr=function(n,t,i){var r="".concat(n,"_").concat(t);console.log("Highlighting ".concat(i," at ").concat(r)),Wt(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(){Wt(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)},wr=c(function(n,t){_e(function(i){var r;return e(e({},i),((r={})[n]=t,r))}),ki(function(t){if(t[n]){var i=e({},t);return delete i[n],i}return t})},[]),yr=c(function(n,t,i,r){nt(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}),Hn(function(a){var o,l,s,u=new Map(a),d=new Map(u.get(n)||new Map),c=d.get(t)||Gn;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(){vi&&(Pi(!1),dn(null),ln(null))},[vi]);var hr=c(function(n){var t;if(void 0===n&&(n=!1),n||(ar({type:"RESET"}),pi.current=null,_t([]),It([]),ri([]),di({}),Pi(!1),Re.current.clear()),$n(""),Vt([]),_n(!1),Je.current="",Ki(""),Xi(null),Ft([]),_e({station:"",tiers:[]}),We(0),ze(!1),tr(null),rt(new Map([["tier_1",new Map],["tier_2",new Map]])),lt(new Map([["tier_1",new Map],["tier_2",new Map]])),dt(new Map([["tier_1",new Map],["tier_2",new Map]])),Hn(new Map([["tier_1",new Map([[0,Gn]])],["tier_2",new Map([[0,Gn]])]])),nt(new Map([["tier_1",new Map],["tier_2",new Map]])),zn(""),Ct(0),$t(0),_e({station:Z,tiers:["Tier 1"]}),n||Ut({}),nt(new Map([["tier_1",new Map],["tier_2",new Map]])),Et(""),ni({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),ki({}),Ni(""),Oi(!0),je(null),Pe(null),gt(new Map),yt([]),yn(!1),Fe(null),fi.current=null,Ue.current=!1,pn.current={},bn.current.clear(),En.current=null,On.current=null,xn(null),Ae(""),ge(j),ye(!1),Se(!1),Ee(!1),en(null),rn([]),ln(null),dn(null),An(null),Tt(!1),Rt(null),Gi(""),Hi(""),Mi(!1),Kn(new Set),Oe.current=!1,Ge.current.clear(),Ze.current=0,Qe.current=null,Ln.current=null,gi.current=-1,hn.current=!1,gn.current=!1,X){X.ruleTitle&&$n(X.ruleTitle),ee&&(_e(function(n){return e(e({},n),{tiers:[ee]})}),On.current=ee.toLowerCase().replace(/ /g,"_")),En.current=X.ruleId;var i=null===(t=null==ne?void 0:ne[te||0])||void 0===t?void 0:t.variantId;if(xn(i||null),ne&&ne.length>0){var r=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;ne.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),rt(a),lt(o),dt(l);var c=ne.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:X.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:X.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"}});_t(c),yt(c),gt(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var v=new Map;ne.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:G(e.variantType||e.variant_type)})}),Hn(new Map([[r,v]])),Ct(null!=te?te:0)}}},[ar,Z,X,ee,ne,te]),br=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)},Tr=c(function(){console.log("variantIds",jt),Pi(!0)},[jt]),Mr={"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;gi.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),Ct(r),gi.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=C(t),a=C(t,"general_details");console.log("--- [CARE] Staging Initial Structure ---",r);var o=C(t,"critical_gaps");if(console.log("isCriticalGap",o),ze(!!o),r){if(r.variant_type&&!("is_variant"in r)){var l=null===(i=Ir(r.variant_type||"").toLowerCase().match(/^(default_variant|default|variant)/i))||void 0===i?void 0:i[0];r.variant_type=G(l)?"Default":"variant",r.isDefault=G(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?Ir(s).toLowerCase().trim().replace(/ /g,"_"):null,d=Boolean(u&&On.current!==u);if(d&&u){var c=On.current;console.log("[Tier Switch Detected]",On.current,"→",u),On.current=u,En.current=null;var v=(jn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===v&&void 0!==St&&(v=St),c&&-1!==v&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(v," from ").concat(c)),rt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),lt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),dt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),Hn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(v),n.set(c,t),n}),_t(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_","")})),jn.current=i,i})),gi.current=-1;var _=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});_e(function(n){return e(e({},n),{tiers:[_]})})}Rt(r),je({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)&&ta(a,r,d),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&En.current&&Nn?_t(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===Nn?e(e({},n),r):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===Nn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Ct(i),$t(function(e){return e+1}),gi.current=i},0),t}):(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&En.current&&!Nn?_t(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(){Ct(a),$t(function(e){return e+1}),gi.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(){Ct(o),$t(function(e){return e+1}),gi.current=o},0),i=n(n([],t,!0),[e(e({},r),{is_new_variant:!0})],!1)}}else setTimeout(function(){Ct(0),$t(function(e){return e+1}),gi.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return jn.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(_t([r]),setTimeout(function(){Ct(0),$t(function(e){return e+1}),gi.current=0},0)),void 0!==r.is_user_accepted_risk&&_t(function(t){var i=!(!X&&!ne),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&ne&&ne.length>0&&(a=ne.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==X?void 0:X.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",is_valid:!0,is_readOnly:e.variantId!==Nn,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=zi||$i,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!==St&&(l=St),-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=N(t)}if(Pe(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){Rt(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(vt)){var r=zi||$i,a=-1;!(!X&&!ne)&&r&&(a=vt.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!==St&&(a=St),-1!==a&&(i=vt[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=(ee||"Tier 1").toLowerCase().replace(/ /g,"_"),s=function(){var e,n=jn.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(Nn)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Nn||(null==e?void 0:e.new_variant_id)===Nn})))return t;if(zi)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===zi||(null==e?void 0:e.new_variant_id)===zi})))return t;var r=null!==(e=null==ne?void 0:ne.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!==St?St: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&&(ki(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}),Ni("")),o.conflict_view&&((null===(r=o.conflict_view.wta)||void 0===r?void 0:r.length)>0&<(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&&dt(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&&(ki({}),Ni(""),lt(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}),dt(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)&&ta(n,null),"save"===(null==n?void 0:n.action)&&(null==n?void 0:n.is_save)&&(Oi(!0),Di(!0)),"discard_rule"===(null==n?void 0:n.action))&&(_t([{variant_id:void 0,rule_description:"",wta:"",wnta:"",variant_type:"variant"}]),yt([]),xn(null),Ct(0),$t(0),An(null),yn(!1),_n(!1),Vt([]),En.current=null,$n(""),tr(null),Hn(new Map([["tier_1",new Map([[0,Gn]])],["tier_2",new Map([[0,Gn]])]])),rt(new Map([["tier_1",new Map],["tier_2",new Map]])),lt(new Map([["tier_1",new Map],["tier_2",new Map]])),dt(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),ln(l))}catch(e){console.error("Failed to parse rule_validation_card JSON",e)}}var s=C(t,"critical_gaps");console.log("isCriticalGap",s),ze(!!s);var u="string"==typeof t?x(t):t;console.log("parsed data from Validation Agent",u);var d=E(t);Fe(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);Oi(v),Di(_);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&&Qi(u.edit_variant_id),"edit"!==p&&"edit_current_rule"!==p||!f||Xi(f),g&&(Qi(null),Xi(null)),"discard"===p)return console.log("Action 'discard' received: Resetting UI state but preserving chat."),gn.current=!0,hr(!0),_t([]),pi.current=null,void(fi.current=null);Ki(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)&&!ne;(null==u?void 0:u.is_valid)?(ki({}),Rt(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(vt)&&h&&(y=h,vt.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)||!X&&!ne)return w;console.log("inside edit flow merge");var b=ne||[],T=f,M=T?b.findIndex(function(e){return e.variantId===T||e.variant_id&&e.variant_id===T||e.id&&e.id===T}):-1;if(-1===M&&(null==u?void 0:u.set_variant_id)&&(M=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===M&&T&&Array.isArray(vt)&&(M=vt.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!==M){var A,I,k,S=b[M]||(null==vt?void 0:vt[M]),C=(null==S?void 0:S.tier_id)||(null==S?void 0:S.tierId)||"1",N=(null==ee?void 0:ee.toLowerCase().replace(/ /g,"_"))||"tier_".concat(C);if(gi.current!==M&&(Ct(M),gi.current=M),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)?I=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)?I=null!==(v=null==u?void 0:u.wnta)&&void 0!==v?v:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(I=null!==(_=null==t?void 0:t.wnta)&&void 0!==_?_:""),void 0!==A){var x=Ir(A);kr(N,M,A,x,ot,lt,null==u?void 0:u.conflict_view),mr(N,M,"wta")}if(void 0!==I){var E=Ir(I);kr(N,M,I,E,ut,dt,null==u?void 0:u.conflict_view),mr(N,M,"wnta")}if(m(u,"rule_description")&&void 0!==(null==u?void 0:u.rule_description)?k=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)&&(k=null!==(g=null==t?void 0:t.rule_description)&&void 0!==g?g:""),void 0!==k){var O=Ir(k);rt(function(e){var n=new Map(e),t=new Map(n.get(N)||new Map);return t.set(M,O),n.set(N,t),n}),mr(N,M,"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&&(Hn(function(e){var n,i,r,a,o,l,s=new Map(e),u=new Map(s.get(N)||new Map);return u.set(M,{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(N,u),s}),mr(N,M,"order_enabled"),mr(N,M,"advertiser_enabled"),mr(N,M,"respect_inventory_code"),mr(N,M,"respect_break_code")),_t(function(t){if(!Array.isArray(t)||M<0||!t[M])return t;var i=n([],t,!0),r=e({},i[M]);return void 0!==A&&(r.wta=A),void 0!==I&&(r.wnta=I),void 0!==k&&(r.rule_description=Ir(k)),L&&(r.scheduling_config=L),console.log("updated variantxxx",r),i[M]=r,i});var R=null==t?void 0:t.variant_type;R&&_t(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[M]=e(e({},i[M]||{}),{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?(Tt(!0),m&&m!==fi.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),Mi(!0),Gi("Loading a variant"),console.log("reaching here in new variant flow"),Hi("This may take a moment as we update the rule with the new variant."),fi.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(Tt(!1),fi.current=null),d&&Vt(d))},"Rule comparison results":function(e){try{var n=e;if("string"==typeof e)try{n=JSON.parse(e)}catch(t){n=x(e)||[]}if(!Array.isArray(n)){if(!n||"object"!=typeof n)return void console.error("[Rule comparison results] Data is not an array:",e);n=[n]}var t=n.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}});rn(t)}catch(e){console.error("[Rule comparison results] Critical Handler Error:",e)}}},Ar=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},Ir=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},kr=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)||"",_=Ar(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&&(zt(function(e){return new Set(n(n([],Array.from(e),!0),g,!0))}),setTimeout(function(){zt(function(e){var n=new Set(e);return g.forEach(function(e){return n.delete(e)}),n})},1500))}}},Sr=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(){xt&&!Oe.current&&"save this learning"!==xt.toLowerCase()&&(Se(!1),Ae(""),gi.current=null!=St?St:-1)},[xt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Dn.current=ii,Array.isArray(vt)&&vt.length>0){var c=oi||"local-".concat(Date.now()),v=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],_={},p=pi.current||[];vt.forEach(function(t,i){var r,a;if(t){t.is_readOnly||(Ze.current=i);var o=i;if((null==t?void 0:t.variant_id)&&ne)-1!==(l=ne.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if(zi&&ne&&1===vt.length){var l;-1!==(l=ne.findIndex(function(e){return e.variantId===zi}))&&(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=Sr(u).map(function(e){return e.toLowerCase().replace(/ /g,"_")}),c=d.length>0?d:fn.current.length>0?fn.current:["tier_1"];c.length>0&&(fn.current=c),console.log("prevTierRef.current",fn.current,"targetTiers",c);var f=Ir(t.title);f&&f!==Ir(null==s?void 0:s.title)&&!t.is_readOnly&&function(e,n,t,i,r,a){var o=Ir(i);o&&o!==r&&(mr(e,n,t),a(o))}("global",0,"ruleTitle",t.title,Zn,$n),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=Ir(t.rule_description),w=(null===(l=it.get(r))||void 0===l?void 0:l.get(o))||"",y=Ir(w);g&&(m!==y||""===m&&""!==w)&&(rt(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}),mr(r,o,"ruleDescription"));var h=!1===(null==Lt?void 0:Lt.is_valid),b=Ir(t.wta),T=Ir(null==c?void 0:c.wta),M=(null===(s=ot.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&M.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==T||""===b&&M.length>0||0===M.length&&""!==b)&&(kr(r,o,t.wta,b,ot,lt,null==Lt?void 0:Lt.conflict_view),mr(r,o,"wta"));var A=Ir(t.wnta),I=Ir(null==c?void 0:c.wnta),k=(null===(u=ut.get(r))||void 0===u?void 0:u.get(o))||[];if(!(h&&""===A&&k.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(A!==I||""===A&&k.length>0||0===k.length&&""!==A)&&(kr(r,o,t.wnta,A,ut,dt,null==Lt?void 0:Lt.conflict_view),mr(r,o,"wnta")),t.scheduling_config||f||t.variant_type||t.variantType){var S=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}},C=null==c?void 0:c.scheduling_config,N=null===(d=Un.get(r))||void 0===d?void 0:d.get(o),x=t.variant_type||t.variantType,E=x?G(x):void 0,O=JSON.stringify(S)!==JSON.stringify(C),L=void 0!==E&&E!==(null==N?void 0:N.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(Ut(function(e){return R(e,S)}),O||L){Ut(function(e){return R(e,S)});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,S,Un);D.forEach(function(e){return mr(r,o,e)}),Kn(function(e){return new Set(e).add("config")}),Hn(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)||Gn;return c.set(o,e(e(e(e(e(e({},v),S.order_rules&&{order_rules:{enabled:!!(null===(t=S.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=S.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)}}),S.advertiser_rules&&{advertiser_rules:{enabled:!!(null===(a=S.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(l=S.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)||0)/60)}}),S.inventory_rules&&{inventory_rules:{respect_inventory_code:!!(null===(s=S.inventory_rules)||void 0===s?void 0:s.respect_inventory_code)}}),S.break_code_rules&&{break_code_rules:{respect_break_code:!!(null===(u=S.break_code_rules)||void 0===u?void 0:u.respect_break_code)}}),void 0!==E&&{is_default_enabled:E})),d.set(r,c),d}),nt(function(e){var n=new Map(e),t=new Map(n.get(r)||new Map),i=t.get(o)||new Set;return S.order_rules&&i.add("order_rules"),S.advertiser_rules&&i.add("advertiser_rules"),S.inventory_rules&&i.add("inventory_rules"),S.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=Ar(j[e]),t="ruleTitle"===e||"scopeData"===e?e:"".concat(e,"_").concat(r);n&&(n!==Rn.current[t]&&(Rn.current[t]=n,Vn.current[t]=!0,_[t]={reasoning:n,associatedCitations:[],tier:r,variantIndex:o}))}),t.conflictingConditions&&(ki(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}),Kn(function(e){return new Set(n(n([],Array.from(e),!0),["conditions"],!1))}))})}});var f=-1,g=!(!X&&!ne),m="edit"===Wi||"edit_current_rule"===Wi,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(fi.current&&bt)-1!==(f=vt.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===fi.current||(null==e?void 0:e.variant_id)&&e.variant_id===fi.current||(null==e?void 0:e.id)&&e.id===fi.current}))&&(fi.current=null);else if(zi||$i){var h;(h=zi||$i)&&(f=y(vt,h))}else if(re&&Array.isArray(vt)&&vt.length>0){for(b=vt.length-1;b>=0;b--)if(vt[b]&&!(null===(i=vt[b])||void 0===i?void 0:i.is_readOnly)){f=b;break}}else null==te||pi.current&&0!==pi.current.length||(f=te);else if((h=zi||$i||fi.current)&&m&&(f=y(vt,h)),!m&&-1===f&&Array.isArray(vt)&&vt.length>0){for(var b=vt.length-1;b>=0;b--)if(vt[b]&&!(null===(t=vt[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=vt.length-1)}-1!==f&&St!==f&&(gi.current===f||Ue.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),Ct(f),gi.current=f));var T=vt[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=Sr(l),d=s?Sr(s):[],_e(function(n){return e(e({},n),{tiers:u})}),u.forEach(function(e){var n=e.trim();d.includes(e)||mr("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 M=T.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(M)&&(_e(function(n){return e(e({},n),{station:M})}),mr("global",0,"scope_station"))}T.wtl&&zn(T.wtl)}pi.current=vt.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&&(ar({type:"SAVE_CITATIONS",requestId:c,reasoningMap:_,rawCitations:ii}),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:or,currentCitations:ii}),ni(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}))}},[vt,ii,oi]),d(function(){var t=Object.keys(Vn.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],ii,!0)}),Vn.current={},di(function(n){return e(e({},n),i)})}},[ii]);var Cr=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==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==qn?void 0:qn.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==$?void 0:$.ruleSetDesc)||""}}})},Nr=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(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"];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:{respect_break_code:"bool",respect_inventory_code:"bool",order_global_min_separation_seconds:"int",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",advertiser_global_min_separation_seconds:"int",advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",advertiser_exemption_priority_code_list:"array",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",break_code_exemption_priority_code_list:"array",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",inventory_exemption_priority_code_list:"array",override_priority_code:"str",custom_sep_time_for_entities:"object"}},config_data:{scheduling_config:n}}},xr=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},Er=function(e,n,t){void 0===t&&(t="variantType");var i=null==e?void 0:e[n];if(!i)return{label:br(e),isDefault:!1};var r=i[t]||"",a=G(r);return{label:"variant ".concat(n+1),isDefault:a}},Or=function(e,n){var t=G(e);return{label:"variant ".concat(n+1),isDefault:t}},Lr=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=Un.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":G(t)?"Default":"Variant"},Rr=function(n,o){return void 0===o&&(o=!1),t(void 0,void 0,void 0,function(){var n,t,l,s,u,d,c,v,p,g,w,h,b,T,M;return i(this,function(i){switch(i.label){case 0:Cr(ve.tiers),n=Ze.current,t=xr(et,Jt,Un,n),i.label=1;case 1:return i.trys.push([1,3,,4]),ge(q),Ae(""),l=Nr(t),s=m(),u=[],d=[],c=(vt||[])[n]||{},console.log("originalItem check :",c,n),ve.tiers.forEach(function(t){var i,r,a,o,v,_,p,f=t.toLowerCase().replace(/ /g,"_");d.push(f);var g=(null===(i=it.get(f))||void 0===i?void 0:i.get(n))||"",m=(null===(r=ot.get(f))||void 0===r?void 0:r.get(n))||[],w=(null===(a=ut.get(f))||void 0===a?void 0:a.get(n))||[],h=[e(e({},l&&{config:e({master_name:qn.CONFIG_MASTER_NAME},l)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:s,variant:Ir(g),conditions_whentoapply:m.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:w.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(_=null===(v=null===(o=Un.get(f))||void 0===o?void 0:o.get(n))||void 0===v?void 0:v.is_default_enabled)||void 0===_||_,tier_id:(null===(p=Le.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===f||e.tier_name.toLowerCase()===f.replace(/_/g,"")}))||void 0===p?void 0:p.tier_id)||"",topic_id:null,scope_id:(null==$?void 0:$.ruleSetId)||"",question_title:Zn,variantType:Lr(f,n,c.variant_type||c.variantType),instantLearningType:qn.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:"019e276d-34df-7761-b3c9-c813eee8520c",modeId:"019e1e39-2030-7775-8312-0ad525700588"})];u.push(y(h,qn.ASSISTANT_NAME))}),[4,Promise.all(u)];case 2:return v=i.sent(),Ee(!1),console.log("✅ All feedback published:",v),ge(V),ye(!0),p=new Map,v.forEach(function(e,n){var t,i,r=d[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=p.get(r)||[];o.push({id:a,action:"new"}),p.set(r,o)}}),A.getState().setCreatedVariantInfo(Array.from(p.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(b=mi.current)||void 0===b||b.show({severity:"success",sticky:!1,life:6e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),Ce.current=setTimeout(function(){Ei||o?(console.log("Closing modal after save success",{isCloseModal:Ei,forceClose:o}),ea()):hr(!0)},3e3),[3,4];case 3:return g=i.sent(),console.error("❌ Error publishing feedback:",g),Ee(!1),ge(P),Se(!0),w=(null===(T=null==g?void 0:g.response)||void 0===T?void 0:T.data)||{},console.log("errorData: ",w),(h="Variant already exists"===(null==w?void 0:w.message))||409===(null==g?void 0:g.status)?Ae('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>'):Ae(((null==w?void 0:w.message)||(null==w?void 0:w.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(M=mi.current)||void 0===M||M.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:h||409===(null==g?void 0:g.status)?"Similar rule already exists. Please update and try again.":(null==w?void 0:w.message)||(null==w?void 0:w.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Dr=function(){return t(void 0,void 0,void 0,function(){var t,o,l,s,u,d,c,v,p,g,w,b,T,M,k,S,C,N,x,E,O,L,R,D,j,J;return i(this,function(i){switch(i.label){case 0:t=A.getState().tiers,o=xr(et,Jt,Un),l=Nr(o),s=Ze.current,u=(vt||[])[s]||{},d=(null==Lt?void 0:Lt.variant_type)||u.variant_type||"",i.label=1;case 1:for(i.trys.push([1,3,,4]),ge(q),Ae(""),v=(c=ne||[]).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=ve.tiers[0])||void 0===L?void 0:L.toLowerCase().replace(/ /g,"_"))||"tier_1",g=(null===(R=it.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=[],M=[],k=Cr(ve.tiers),ve.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=it.get(i),o=ot.get(i),s=ut.get(i);w.forEach(function(t,c){var _,p,f,g,w,b,A,I,S,C,N,x,E,O,L,R,D,j,V,P,q,J,U,H,B,W,K,Y,z=(null==a?void 0:a.get(c))||t.description||"",Q=(null==o?void 0:o.get(c))||[],Z=(null==s?void 0:s.get(c))||[];if(t.isNewVariant){M.push({tierKey:i,payloadType:"new"});var ee=xr(et,Jt,Un,c),ne=Nr(ee);console.log("variant in save edit add part :",t,u);var te={status:"approved",metadata:e(e({userName:null!==(_=null==ir?void 0:ir.firstname)&&void 0!==_?_:"",userEmailId:null!==(p=null==ir?void 0:ir.email)&&void 0!==p?p:"",llm:qn.MODEL,isVariantFlow:!0},ne&&{config:e({master_name:qn.CONFIG_MASTER_NAME},ne)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:v||m(),variant:Ir(z),conditions_whentoapply:Q.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:k[0]||{name:qn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:qn.CUSTOM_SCOPE_GROUP_NAME,description:(null==$?void 0:$.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=Un.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:G(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:qn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(ve.station,"RuleSet"),description:null},categories:[{id:null,value:qn.CATEGORY,description:qn.CATEGORY}],originalQuestion:Zn,questionId:null==X?void 0:X.ruleId,variantType:Lr(i,c,u.variant_type||""),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==ir?void 0:ir.email)&&void 0!==b?b:"",instantLearningType:qn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(I=null===(A=(vt||[])[c])||void 0===A?void 0:A.is_user_accepted_risk)&&void 0!==I?I:null==Lt?void 0:Lt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",te),T.push(y(te,qn.ASSISTANT_NAME))}else{M.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var ie=t.variantId===zi,re=Lr(i,c,ie?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",re,ie,t,zi);var ae={variantId:t.variantId,ruleDesc:(null==$?void 0:$.ruleSetDesc)||"",whenToApply:Q.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!==(N=null===(C=null===(S=Un.get(i))||void 0===S?void 0:S.get(c))||void 0===C?void 0:C.is_default_enabled)&&void 0!==N?N:G(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==$?void 0:$.ruleSetId)||"",description:Ir(z)||"",topic:"".concat(ve.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=(vt||[])[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=(ft.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=F(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ue=se(Zn)===se(oe.title),de=se(z)===se(oe.rule_description),ce=se(ae.whenToApply)===se(oe.wta),_e=se(ae.whenNotToApply)===se(oe.wnta),pe=!!ae.isDefault===G(oe.variant_type),fe=oe.scheduling_config||{},ge=null!==(D=null!==(L=fe.order_global_min_separation_seconds)&&void 0!==L?L:null===(R=fe.order_rules)||void 0===R?void 0:R.global_min_separation_seconds)&&void 0!==D?D:0,me=null!==(P=null!==(j=fe.advertiser_global_min_separation_seconds)&&void 0!==j?j:null===(V=fe.advertiser_rules)||void 0===V?void 0:V.global_min_separation_seconds)&&void 0!==P?P:0,we=null!==(U=null!==(J=null===(q=fe.inventory_rules)||void 0===q?void 0:q.respect_inventory_code)&&void 0!==J?J:fe.respect_inventory_code)&&void 0!==U&&U,ye=null!==(W=null!==(B=null===(H=fe.break_code_rules)||void 0===H?void 0:H.respect_break_code)&&void 0!==B?B:fe.respect_break_code)&&void 0!==W&&W,he=(null===(K=Un.get(i))||void 0===K?void 0:K.get(c))||Gn,be=he.order_rules.enabled===ge>0&&he.order_rules.global_min_separation_seconds===Math.floor(ge/60)&&he.advertiser_rules.enabled===me>0&&he.advertiser_rules.global_min_separation_seconds===Math.floor(me/60)&&he.inventory_rules.respect_inventory_code===we&&he.break_code_rules.respect_break_code===ye;ue&&de&&ce&&_e&&pe&&be&&(le=!1)}le?(console.log("payloadv (update existing variant)",ae),T.push(h(ae,null!==(Y=null==ir?void 0:ir.email)&&void 0!==Y?Y:""))):(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 S=i.sent(),console.log("✅ All variants updated:",S),ge(V),ye(!0),Ee(!1),C=new Map,S.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=M[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=C.get(r.tierKey)||[];l.push({id:o,action:r.payloadType}),C.set(r.tierKey,l)}}}),A.getState().setCreatedVariantInfo(Array.from(C.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=mi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ce.current=setTimeout(function(){ea()},3e3),[3,4];case 3:return N=i.sent(),console.error("❌ Error updating variant:",N),ge(P),Se(!0),Ee(!1),x=(null===(j=null==N?void 0:N.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",x),(E="Variant already exists"===(null==x?void 0:x.message))||409===(null==N?void 0:N.status)?Ae('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>'):Ae(((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===(J=mi.current)||void 0===J||J.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:E||409===(null==N?void 0:N.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,M,k,S,C,N,x,E,O,L,R,D,j,J;return i(this,function(i){switch(i.label){case 0:n=A.getState().tiers,t=xr(et,Jt,Un),o=Nr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),ge(q),Ae(""),0===(l=Array.isArray(vt)?vt:[]).length?(console.warn("No variants found to save."),ge(P),[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=Cr(ve.tiers),ve.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=it.get(i),s=ot.get(i),u=ut.get(i);l.forEach(function(n,l){var _,f,y,b,T,M,A,I,k,S,C,N,x,E,O,L,R,D,j,V,P,q,J,U,H,B,W,K=(null==a?void 0:a.get(l))||n.rule_description||n.description||"",Y=(null==s?void 0:s.get(l))||[],z=(null==u?void 0:u.get(l))||[];if(n.is_new_variant){var Q=xr(et,Jt,Un,l),X=Nr(Q),ee=Lr(i,l,n.variant_type||n.variantType||""),ne={status:"approved",metadata:e(e({userName:null!==(_=null==ir?void 0:ir.firstname)&&void 0!==_?_:"",userEmailId:null!==(f=null==ir?void 0:ir.email)&&void 0!==f?f:"",llm:qn.MODEL,isVariantFlow:!0},X&&{config:e({master_name:qn.CONFIG_MASTER_NAME},X)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Ir(K),conditions_whentoapply:Y.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:w[0]||{name:qn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==$?void 0:$.ruleSetId)||"",value:{scopeName:(null==$?void 0:$.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:qn.CUSTOM_SCOPE_GROUP_NAME,description:(null==$?void 0:$.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(T=null===(b=null===(y=Un.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==T?T:G(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:qn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(t.split(" ")[1]||"1"),tier_id:(null==r?void 0:r.tier_id)||""},topic:{id:null,value:"".concat(ve.station||Z,"RuleSet"),description:null},categories:[{id:null,value:qn.CATEGORY,description:qn.CATEGORY}],originalQuestion:Zn,questionId:En.current||null,variantType:ee,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(M=null==ir?void 0:ir.email)&&void 0!==M?M:"",instantLearningType:qn.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==Lt?void 0:Lt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ne),v.push({payload:ne,tierKey:i}),g.push({tierKey:i})}else if(null==n?void 0:n.variant_id){p.push({tierKey:i,existingId:n.variant_id});var te=(null==n?void 0:n.variant_id)&&n.variant_id===nr?(null==Lt?void 0:Lt.variant_type)||n.variant_type||n.variantType||"":n.variant_type||n.variantType||"",ie=(ee=Lr(i,l,te),{variantId:n.variant_id,ruleDesc:(null==$?void 0:$.ruleSetDesc)||"",whenToApply:Y.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!==(S=null===(k=null===(I=Un.get(i))||void 0===I?void 0:I.get(l))||void 0===k?void 0:k.is_default_enabled)&&void 0!==S?S:G(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!==(C=null==r?void 0:r.tier_priority)&&void 0!==C?C:null},scope_id:(null==$?void 0:$.ruleSetId)||"",description:Ir(K)||"",topic:"".concat(ve.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:ee,is_user_accepted_risk:!!(null!==(N=null==n?void 0:n.is_user_accepted_risk)&&void 0!==N?N:null===(x=(vt||[])[l])||void 0===x?void 0:x.is_user_accepted_risk),is_enabled:n.is_enabled}),re=(ft.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=F(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},le=oe(Zn)===oe(re.title),se=oe(K)===oe(re.rule_description),ue=oe(ie.whenToApply)===oe(re.wta),de=oe(ie.whenNotToApply)===oe(re.wnta),ce=!!ie.isDefault===G(re.variant_type),_e=re.scheduling_config||{},pe=null!==(L=null!==(E=_e.order_global_min_separation_seconds)&&void 0!==E?E:null===(O=_e.order_rules)||void 0===O?void 0:O.global_min_separation_seconds)&&void 0!==L?L:0,fe=null!==(j=null!==(R=_e.advertiser_global_min_separation_seconds)&&void 0!==R?R:null===(D=_e.advertiser_rules)||void 0===D?void 0:D.global_min_separation_seconds)&&void 0!==j?j:0,ge=null!==(q=null!==(P=null===(V=_e.inventory_rules)||void 0===V?void 0:V.respect_inventory_code)&&void 0!==P?P:_e.respect_inventory_code)&&void 0!==q&&q,me=null!==(H=null!==(U=null===(J=_e.break_code_rules)||void 0===J?void 0:J.respect_break_code)&&void 0!==U?U:_e.respect_break_code)&&void 0!==H&&H,we=(null===(B=Un.get(i))||void 0===B?void 0:B.get(l))||Gn,ye=we.order_rules.enabled===pe>0&&we.order_rules.global_min_separation_seconds===Math.floor(pe/60)&&we.advertiser_rules.enabled===fe>0&&we.advertiser_rules.global_min_separation_seconds===Math.floor(fe/60)&&we.inventory_rules.respect_inventory_code===ge&&we.break_code_rules.respect_break_code===me;le&&se&&ue&&de&&ce&&ye&&(ae=!1)}ae?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ie),c.push(h(ie,null!==(W=null==ir?void 0:ir.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=[],M=0,k=v,i.label=3;case 3:if(!(M<k.length))return[3,8];S=k[M],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(S.payload,qn.ASSISTANT_NAME)];case 5:return C=i.sent(),T.push(C),[3,7];case 6:throw N=i.sent(),console.error("❌ Error publishing new variant:",N),N;case 7:return M++,[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)}}),A.getState().setCreatedVariantInfo(Array.from(x.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),ge(V),ye(!0),Ee(!1),Ue.current=!1,null===(D=mi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ce.current=setTimeout(function(){ea()},3e3),[3,10];case 9:return E=i.sent(),console.error("❌ Error updating variant:",E),ge(P),Se(!0),Ee(!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)?Ae('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>'):Ae(((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===(J=mi.current)||void 0===J||J.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(_,{className:I.iconError}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageError)},{children:L||409===(null==E?void 0:E.status)?"Similar rule already exists. Please update and try again.":(null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,10];case 10:return[2]}})})},Vr=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(){Ri&&!vi&&(console.log("isSaveRule received from agent — calling publish APIs directly."),Di(!1),X||ne?Dr():!0===Ue.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]),ge(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=Le.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:Zn,orgName:qn.ORGANIZATION_NAME,scope_id:(null==$?void 0:$.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=ve.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 Rr(),[3,6];case 5:return o=u.sent(),l=new Map,ve.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Rr(),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Ri,vi]);var Pr=(null===(U=(null===(J=null==ve?void 0:ve.tiers)||void 0===J?void 0:J[0])||ee||"Tier 1")||void 0===U?void 0:U.toLowerCase().replace(/ /g,"_"))||"tier_1",qr=null!==(H=null!=St?St:te)&&void 0!==H?H:0,Fr=null!=St,Gr=Fr?null==vt?void 0:vt[qr]:null,Jr=vt&&(null==vt?void 0:vt.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&qt.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&jt.includes(e.variant_id))})),Ur=(null==Gr?void 0:Gr.new_variant_id)&&qt.includes(Gr.new_variant_id)?Gr.new_variant_id:(null==Jr?void 0:Jr.new_variant_id)&&qt.includes(Jr.new_variant_id)?Jr.new_variant_id:"",Hr=!(!X&&!ne),Br=function(n){var t={},i=ve.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),r=(null==ve?void 0:ve.station)+"RuleSet",a=i.map(function(e){var n=Le.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])||Pr,f=it.get(p),g=ot.get(p),m=ut.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||"",M=Un.get(p),A=null==M?void 0:M.get(o),I={};A&&Object.keys(A).length>0?I=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&&(I=n.scheduling_config),t[_]={rule_title:Zn,variant_description:w,wta:h,ruleset_id:(null==$?void 0:$.ruleSetId)||"",tier_id:a,wnta:T,scope:i,scope_rule_set:r,scheduling_config:I,is_user_accepted_risk:!(null===(v=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(vt||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===v||!v)}}),t};wn&&console.log("customMetaData.ui_state for addvariant flow",Br(wt));var Wr={send_metadata_to_orchestrator:!1,default:["scope"],ui_state:Hr?{variants:function(){var n={},t=Un.get(Pr);if(!t)return n;var i=it.get(Pr),r=ot.get(Pr),a=ut.get(Pr),o=ve.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),l=(null==ve?void 0:ve.station)+"RuleSet",s=o.map(function(e){var n=Le.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==ne?void 0:ne[d])||void 0===c?void 0:c.variantId,w=(vt||[])[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 ")||"",M=((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),I={};A&&Object.keys(A).length>0&&(I=e(e({},A),{order_rules:e(e({},A.order_rules),{global_min_separation_seconds:60*((null===(v=A.order_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},A.advertiser_rules),{global_min_separation_seconds:60*((null===(_=A.advertiser_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)})})),n[h]={rule_title:Zn,variant_description:b,wta:T,ruleset_id:(null==$?void 0:$.ruleSetId)||"",tier_id:s,wnta:M,scope:o,scope_rule_set:l,scheduling_config:I,is_user_accepted_risk:!(null===(g=null!==(p=null==w?void 0:w.is_user_accepted_risk)&&void 0!==p?p:null===(f=null==ne?void 0:ne[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=(vt||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:vn?s=-1:wn||(s=qr),{new_current_variant:-1!==s?{rule_title:Zn,rule_description:(null===(n=it.get(Pr))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=ot.get(Pr))||void 0===t?void 0:t.get(s))||void 0===i?void 0:i.map(function(e){return Vr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",wnta:(null===(a=null===(r=ut.get(Pr))||void 0===r?void 0:r.get(s))||void 0===a?void 0:a.map(function(e){return Vr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",scope:ve.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),scope_rule_set:(null==ve?void 0:ve.station)+"RuleSet",scheduling_config:function(){var n,t,i,r=null===(n=Un.get(Pr))||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=(vt||[])[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:wn?Br(wt):{}}}(),rule_id_in_current_session:At,new_variant_id:function(){var e;return Fr&&X?(null===(e=null==ne?void 0:ne[qr])||void 0===e?void 0:e.variantId)?null:Ur:null}(),edit_variant_id:Nn,rule_id:En.current,ruleset_id:(null==$?void 0:$.ruleSetId)||"",current_variants_length:X?Array.isArray(vt)&&vt.length>0?Math.max((null===(B=null==X?void 0:X.variants)||void 0===B?void 0:B.length)||0,vt.length):null===(W=null==X?void 0:X.variants)||void 0===W?void 0:W.length:void 0,tiers:Le,authToken:(null==ir?void 0:ir.accessToken)||""},Kr=br(wt),Yr={ruleTitle:Zn,scopeData:ve,variantsByTier:Array.from(Un.keys()).reduce(function(n,t){var i=Un.get(t)||new Map,r=it.get(t)||new Map,a=ot.get(t)||new Map,o=ut.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=(vt||[])[n]||{};console.log("Original item for tier",t,"index",n,":",d);var c={label:"",isDefault:!1};if(d.is_variant&&!G(d.variant_type))c={label:"",isDefault:!1};else if(ne&&ne.length>0){c=Er(ne,n,"variantType"),console.log("Found matching variant at index",n,":",c);var v=ne[n];if(v){if(!c.label){var _=v.variantType||"",p=G(_);c={label:"variant ".concat(n+1),isDefault:p}}if(v.variantId===zi)(g=d.variant_type||(null==Lt?void 0:Lt.variant_type))&&(c=Or(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:br(ne),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(wt&&wt.length>0){if(c=Er(wt,n,"variant_type"),console.log("Found matching variant at index",n,":",c),Ue.current){var f=wt[n];if((null==f?void 0:f.variant_id)===nr||(null==f?void 0:f.variantId)===nr)(g=d.variant_type||(null==Lt?void 0:Lt.variant_type))&&(c=Or(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:Kr,isDefault:G(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)||Gn,isReadOnly:d.is_readOnly||!1,is_variant:d.is_variant||!1,reasoning:{ruleDescription:Ar(y),whenToApply:Ar(d.wta),whenNotToApply:Ar(d.wnta),configData:Ar(d.action)}}}),n},{}),citation:ei,fieldCitations:ui,citations:ii};console.log("templateState",Yr);var zr={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;$n(i),ki(function(n){if(n.ruleTitle){var t=e({},n);return delete t.ruleTitle,t}return n})},setRuleDescription:function(e,n,t){return ur(e,n,t)},addWhenToApply:function(e,n){return dr(e,n)},removeWhenToApply:function(e,n,t){return cr(e,n,t)},editWhenToApply:function(e,n,t,i){return vr(e,n,t,i)},addWhenNotToApply:function(e,n){return _r(e,n)},removeWhenNotToApply:function(e,n,t){return pr(e,n,t)},editWhenNotToApply:function(e,n,t,i){return fr(e,n,t,i)},addNewVariant:function(e){return gr(e)},onScopeChange:wr,onConfigChange:function(e,n,t,i){return yr(e,n,t,i)}},Qr={},Zr={};Un.forEach(function(n,t){Qr[t]=new Map,Zr[t]=new Map,n.forEach(function(n,i){Qr[t].set(i,[e({key:"order_rules",label:"Order"},n.order_rules),e({key:"advertiser_rules",label:"Advertiser"},n.advertiser_rules)]),Zr[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 $r=v(function(){if(ee){if(1===ve.tiers.length)return 0;var e=ve.tiers.findIndex(function(e){return e.toLowerCase()===ee.toLowerCase()});return e>=0?e:0}},[ee,ve.tiers]),Xr=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:Qr,togglesByTier:Zr,highlights:Bt,highlightedIds:Yt,openSections:Wn,setOpenSections:Kn,setSendMessageInChat:Et,isAiStreaming:vi,defaultTierOpen:$r,defaultVariantOpen:vn?void 0:St,autoScrollVariantIndex:vn?void 0:St,activeVariantAccordionIndex:vn?void 0:St,setActiveVariantAccordionIndex:function(e){Ct(e),null!=e&&setTimeout(function(){_n(!1)},100)},validationErrors:Ii,activeEditId:Mn,setActiveEditId:An,pendingEditId:kn,setPendingEditId:Sn,conflictReason:Ci,usedFor:X||ne?"Edit":"Create"},Fn),{scrollTrigger:Zt});console.log(St,"editVariantIndex checking"),d(function(){},[Y]),d(function(){if(!vi&&bt&&!!(!X&&!ne)){var e=n([],vt,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||vt.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),Ct(e))}},[vi,bt]);var ea=function(){Ce.current&&(clearTimeout(Ce.current),Ce.current=null),Ue.current=!1,z(),hr()},na=function(){var e={};Zn.trim()||(e.ruleTitle="Rule Title is required"),ve.station||(e.station="Station Rule Set is required"),ve.tiers&&0!==ve.tiers.length||(e.tiers="At least one tier must be selected");return ve.tiers.map(function(e){return e.toLowerCase().replace(/ /g,"_")}).forEach(function(n){var t=it.get(n),i=ot.get(n),r=Un.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 ta(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,M,A,I,k,S,C,N,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,hn.current&&Ln.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(En.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",_),xn(_),_?(-1!==(p=(vt||[]).findIndex(function(e){return e.is_new_variant}))&&(Mi(!0),Gi("Removing new variant..."),Hi("Please wait while we remove new variant.")),_t(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(){Ct(t),$t(function(e){return e+1}),gi.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})})(Hn),f(rt),f(lt),f(dt),Vt(function(e){var t=n([],e,!0);return t.length>p&&t.splice(p,1),t})),!1===hn.current&&(hn.current=!0,-1!==p&&(null===(l=mi.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}))),_n(!1)):(console.log("lastLoadedQuestionIdRef.current in else",En.current),null===En.current&&(Mi(!0),Gi("Adding new variant..."),Hi("Please wait while we add new variant."))),[2];console.log("User Action: fetching fresh variant info for question",t),bn.current.clear(),bn.current.add(t),Mi(!0),Gi("Loading variants..."),console.log("reaching here in load and edit"),Hi("Please wait while we fetch the latest variant data."),hn.current=!0,Ln.current=t,i.label=1;case 1:return i.trys.push([1,5,6,10]),g=Date.now(),[4,b(t,(null==$?void 0:$.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),Mi(!1),Gi(""),null===(u=mi.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(Ue.current=!0,hn.current=!0,h=(null===(d=null==m?void 0:m.data)||void 0===d?void 0:d.ruleTitle)||"",$n(h),T=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,M="tier_1",A="Tier 1",I="1",T&&((k=String(T).match(/(\d+)/))?(S=k[1],I=S,M="tier_".concat(S),A="Tier ".concat(S)):(M=String(T).toLowerCase().trim().replace(/ /g,"_"),A=M.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),I=M.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(A," (ID: ").concat(I,", Key: ").concat(M,")")),_e({station:Z||"global",tiers:[A]}),C=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:G(e.variantType||e.variant_type)}),s.set(n,F(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,M,I,t,_),N=C.transformedVariants,x=C.tierConfigMap,E=C.tierDescMap,O=C.tierWtaMap,L=C.tierWntaMap,gt(function(e){var n=new Map(e);return n.set(M,JSON.parse(JSON.stringify(N))),n}),_t(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),N,!0)}),yt(function(e){var t=(Array.isArray(e)?e:[]).filter(function(e){return"copy"===e.action||e.tier_id&&e.tier_id!==I});return n(n([],t,!0),N,!0)}),yn(!0),En.current=t,xn(_),R=0,_&&-1!==(D=N.findIndex(function(e){return e.variant_id===_}))&&(R=D),Ct(R),$t(function(e){return e+1}),gi.current=R,_n(!1),Hn(function(e){var n=new Map(e);return n.set(M,x),n}),rt(function(e){var n=new Map(e);return n.set(M,E),n}),lt(function(e){var n=new Map(e);return n.set(M,O),n}),dt(function(e){var n=new Map(e);return n.set(M,L),n}),ki({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(v=mi.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 hn.current=!1,Mi(!1),Gi(""),Hi(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&En.current&&Nn?(console.log("inside edit variant flow",En.current,Nn),_t(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)===Nn?e(e({},n),a):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===Nn});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Ct(i),$t(function(e){return e+1}),gi.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)&&En.current&&!Nn?(console.log("inside add new variant flow",En.current,Nn),Mi(!0),Gi("Adding new variant..."),Hi("Please wait while we add new variant."),[4,new Promise(function(e){return setTimeout(e,3e3)})]):[3,9];case 8:i.sent(),Mi(!1),Gi(""),Hi(""),_t(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(){Ct(r),$t(function(e){return e+1}),gi.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(){Ct(o),$t(function(e){return e+1}),gi.current=o},0),i=n(n([],t,!0),[e(e({},a),{is_new_variant:!0,is_variant:!0})],!1)}}else setTimeout(function(){Ct(0),$t(0),gi.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return jn.current=i,i}),i.label=9;case 9:return[7];case 10:return[2]}})})}var ia;return console.log("RuleSet in render",$),r(o,{children:[a(g,{ref:mi}),a(k,{open:Y,chatAssistantName:qn.ASSISTANT_NAME,organizationName:qn.ORGANIZATION_NAME,baseUrl:qn.BASE_URL,baseWebsocketUrl:qn.BASE_WEBSOCKET_URL,closeFunction:ea,ThinkingBulbIconComponent:a(D,{}),customSections:a(o,{}),customMetaData:Wr,chatTitle:X?qn.CHAT_TITLE_EDIT.replace("<scope>",(null==$?void 0:$.ruleSetName)||""):qn.CHAT_TITLE.replace("<scope>",(null==$?void 0:$.ruleSetName)||""),formTitle:qn.FORM_TITLE,showSavedMessage:!1,savedMessage:be,isError:ke,errorMessage:Me,isSaving:xe,onSave:function(e){console.log("Save this Learning",e);var n=na();if(Object.keys(n).length>0)return console.log("validation errors",n),void ki(n);Ee(!0),Se(!1),Ae("")},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=na(),Object.keys(e).length>0?(ki(e),[2]):(console.log("✅ Bypass Save: Initiated"),X||ne?[4,Dr()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==Ue.current?[3,4]:[4,jr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),ge(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=Le.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:Zn,orgName:qn.ORGANIZATION_NAME,scope_id:(null==$?void 0:$.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=ve.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,Rr(n,!0)];case 9:return d.sent(),[3,11];case 10:return l=d.sent(),ge(P),s=new Map,ve.tiers.forEach(function(e){s.set(e.toLowerCase().replace(/ /g,"_"),null)}),Rr(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:Mr,aiResponse:vt,setAIResponse:_t,width:"90vw",height:"90vh",sendMessageInChat:xt,template:S.CreateRule,isLoading:fe===q,templateProps:{state:Yr,handlers:zr,uiState:Xr},setSendMessageInChat:Et,onResetChat:function(){hr()},onResetRequest:function(){hi(!0)},isFormDirty:function(){return""!==Zn.trim()||""!==ve.station||ve.tiers.length>0||Array.from(it.values()).some(function(e){return Array.from(e.values()).some(function(e){return""!==e.trim()})})||Array.from(ot.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Array.from(ut.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Un.size>0||et.size>0},initialChatMessage:X?(ia=X.ruleTitle||"this rule",null===(K=null==ne?void 0:ne[null!=te?te:0])||void 0===K||K.is_user_accepted_risk,'<p><span>Welcome back! 👋</span>\n <span>I see you want to edit <strong>"'.concat(ia,'."</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!=de?de:qn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(fe===V||we)return!1;if(!Zn||""===Zn.trim())return!1;if(null!==Mn)return!1;if(!ve.station||""===ve.station.trim())return!1;var e=ve.tiers&&ve.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=it.get(r),o=ot.get(r),l=Un.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!(!Un||0===Un.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})})})})(ot)&&!n(ut)&&!Ye)},setCitations:ri,isLocked:!0,textareaPlaceholder:"Tell me more about this learning..",saveButtonConfig:{label:X?"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:li,isAiStreaming:vi,setIsAiStreaming:_i,showConfirmReset:yi,setShowConfirmReset:hi,confirmReset:function(){hr(),hi(!1),ea()},isLoadingVariants:Ti,mainText:Fi,subText:Ui,proposedRule:Xe,isFetchingComparison:sr,handleOpenComparison:Tr,showComparison:Vi,setShowComparison:Pi,variants:tn,onComparisonLinkClick:lr,targetComparisonVariantId:on,highlightedComparisonField:un,onAddAsVariant:function(){Pi(!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==ir?void 0:ir._id)&&void 0!==a?a:"",user_name:null!==(o=null==ir?void 0:ir.firstname)&&void 0!==o?o:"",user_email:null!==(l=null==ir?void 0:ir.email)&&void 0!==l?l:"",assistant_name:qn.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!==Mn&&(e.target.closest('[data-edit-id="'.concat(Mn,'"]'))||(e.preventDefault(),e.stopPropagation(),Sn(Mn)))},isGlobalEditActive:null!==Mn,initialDraftMessage:oe?ue:"",socketTimeOutInMilliSeconds:qn.SOCKET_TIMEOUT})]})};export{J as default,F as filterAgentText};
|
|
2
2
|
//# sourceMappingURL=InstantLearningModal.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import t from"../../../features/LearningManagement/components/InstantLearningModal.js";var a=function(a){var i=a.pluginPayload||{},n=i.editingRule,r=i.editingTier,o=i.editingVariants,d=i.focusedVariantIndex,c=i.setFocusedVariantIndex,u=i.triggerAddVariant,l=i.triggerFixGaps,s=i.copiedRule,p=i.copiedSourceTier,g=i.copiedTargetTier,m=i.initialDraftMessage,I=i.app_integration_id,w=i.modeId,x={"Separation rule":"I would want to add a separation rule","Max priority rule":"I would want to set a max priority rule","Break code matching":"I would want to add a break code matching rule","Inventory code matching":"I would want to add a inventory window matching rule","Enter a rule description":"I want to add a rule description","Tester Genie":"Loading prompt..."},f="<p><span>Hi! 👋 I'm your Instant Learning Concierge.</span>\n <span>How would you like to get started? You can select an option below or describe the rule you’d like to create.</span>\n ".concat(["Separation rule","Max priority rule","Break code matching","Inventory code matching","Enter a rule description","Tester Genie"].map(function(e){return'<button class="clickable-button" data-value="'.concat(x[e],'">').concat(e,"</button>")}).join(""),"</p>");return e(t,{isOpen:a.isOpen,onClose:a.onClose,initialScope:a.initialScope,ruleSet:a.ruleSet,editingRule:n,editingTier:r,editingVariants:o,focusedVariantIndex:d,setFocusedVariantIndex:c,triggerAddVariant:u,triggerFixGaps:l,copiedRule:s,copiedSourceTier:p,copiedTargetTier:g,initialDraftMessage:m,initialChatMessage:f,applicationIntegrationId:I,modeId:w})};export{a as default};
|
|
2
2
|
//# sourceMappingURL=RadioTrafficLearningRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleContent.d.ts","sourceRoot":"","sources":["../../../../../../src/features/LearningManagement/RuleContent/RuleContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAiB3D;;;GAGG;AACH,UAAU,gBAAgB;IACxB,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,8CAA8C;IAC9C,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,qDAAqD;IACrD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wDAAwD;IACxD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,+CAA+C;IAC/C,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,kDAAkD;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iDAAiD;IACjD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,iBAAiB,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"RuleContent.d.ts","sourceRoot":"","sources":["../../../../../../src/features/LearningManagement/RuleContent/RuleContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAiB3D;;;GAGG;AACH,UAAU,gBAAgB;IACxB,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,8CAA8C;IAC9C,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,qDAAqD;IACrD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wDAAwD;IACxD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,+CAA+C;IAC/C,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,kDAAkD;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iDAAiD;IACjD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,iBAAiB,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA+yB3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|