@e-llm-studio/instant-learning 0.1.1-alpha.7 → 0.1.1-alpha.70
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/IL-OTJ/ILOTJ.js +1 -1
- package/dist/cjs/features/IL-OTJ/ILOTJTest.js +1 -1
- package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js +2 -0
- package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js.map +1 -0
- package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/MessageRendering/RuleValidationCard.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/templates/RuleComparison/RuleComparison.js +1 -1
- package/dist/cjs/features/LearningManagement/LearningManagement.js +1 -1
- package/dist/cjs/features/LearningManagement/LearningTemplateLayout.js +1 -1
- package/dist/cjs/features/LearningManagement/RBAC/AccessManagementPanel.js +2 -0
- package/dist/cjs/features/LearningManagement/RBAC/AccessManagementPanel.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RBAC/AccessPanel.js +2 -0
- package/dist/cjs/features/LearningManagement/RBAC/AccessPanel.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RBAC/AccessPanel.module.css.js +2 -0
- package/dist/cjs/features/LearningManagement/RBAC/AccessPanel.module.css.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/AddScopeModal.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/AddScopeModal.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/ApprovalActionButton.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/ApprovalActionButton.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/ApprovalLearningDialog.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/ApprovalLearningDialog.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/PendingApprovalChip.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/PendingApprovalChip.js.map +1 -0
- package/dist/cjs/features/LearningManagement/RuleContent/RenameScopeModal.js +2 -0
- package/dist/cjs/features/LearningManagement/RuleContent/RenameScopeModal.js.map +1 -0
- 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/apis/scopeApis.js +1 -1
- package/dist/cjs/features/LearningManagement/components/CreateLearningSetModal.js +1 -1
- package/dist/cjs/features/LearningManagement/components/CreateRuleSetLegacyModal.js +2 -0
- package/dist/cjs/features/LearningManagement/components/CreateRuleSetLegacyModal.js.map +1 -0
- package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/cjs/features/LearningManagement/components/ScopeSkeletonLoader.js +2 -0
- package/dist/cjs/features/LearningManagement/components/ScopeSkeletonLoader.js.map +1 -0
- package/dist/cjs/features/LearningManagement/components/ScopeTree/TreeNode.js +1 -1
- package/dist/cjs/features/LearningManagement/components/ScopeTree/TreeSidebar.js +1 -1
- package/dist/cjs/features/LearningManagement/components/StationOnboarding/StationAutocomplete.js +1 -1
- package/dist/cjs/features/LearningManagement/components/StationOnboarding/StationOnboardModal.js +1 -1
- package/dist/cjs/features/LearningManagement/components/ToolTip.js +1 -1
- package/dist/cjs/features/LearningManagement/queries/useApprovalQueries.js +2 -0
- package/dist/cjs/features/LearningManagement/queries/useApprovalQueries.js.map +1 -0
- package/dist/cjs/features/LearningManagement/store/useAppSecRolesStore.js +2 -0
- package/dist/cjs/features/LearningManagement/store/useAppSecRolesStore.js.map +1 -0
- package/dist/cjs/features/LearningManagement/store/useConfigStore.js +1 -1
- package/dist/cjs/features/LearningManagement/store/useLearningTemplateStore.js +1 -1
- package/dist/cjs/features/LearningManagement/store/usePermissionsStore.js +2 -0
- package/dist/cjs/features/LearningManagement/store/usePermissionsStore.js.map +1 -0
- package/dist/cjs/features/LearningManagement/styles/ScopeTree.module.css.js +1 -1
- package/dist/cjs/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js +2 -0
- package/dist/cjs/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.js +2 -0
- package/dist/cjs/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.js.map +1 -0
- package/dist/cjs/plugins/ValueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +2 -0
- package/dist/features/IL-OTJ/ILOTJ.js +1 -1
- package/dist/features/IL-OTJ/ILOTJTest.js +1 -1
- package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js +2 -0
- package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js.map +1 -0
- package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js +1 -1
- package/dist/features/IL-OTJ/_components/MessageRendering/RuleValidationCard.js +1 -1
- package/dist/features/IL-OTJ/_components/templates/RuleComparison/RuleComparison.js +1 -1
- package/dist/features/LearningManagement/LearningManagement.js +1 -1
- package/dist/features/LearningManagement/LearningTemplateLayout.js +1 -1
- package/dist/features/LearningManagement/RBAC/AccessManagementPanel.js +2 -0
- package/dist/features/LearningManagement/RBAC/AccessManagementPanel.js.map +1 -0
- package/dist/features/LearningManagement/RBAC/AccessPanel.js +2 -0
- package/dist/features/LearningManagement/RBAC/AccessPanel.js.map +1 -0
- package/dist/features/LearningManagement/RBAC/AccessPanel.module.css.js +2 -0
- package/dist/features/LearningManagement/RBAC/AccessPanel.module.css.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.js +2 -0
- package/dist/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/AddScopeModal.js +2 -0
- package/dist/features/LearningManagement/RuleContent/AddScopeModal.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/ApprovalActionButton.js +2 -0
- package/dist/features/LearningManagement/RuleContent/ApprovalActionButton.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/ApprovalLearningDialog.js +2 -0
- package/dist/features/LearningManagement/RuleContent/ApprovalLearningDialog.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/PendingApprovalChip.js +2 -0
- package/dist/features/LearningManagement/RuleContent/PendingApprovalChip.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/RenameScopeModal.js +2 -0
- package/dist/features/LearningManagement/RuleContent/RenameScopeModal.js.map +1 -0
- package/dist/features/LearningManagement/RuleContent/RuleContent.js +1 -1
- package/dist/features/LearningManagement/apis/apiConfig.js +1 -1
- package/dist/features/LearningManagement/apis/scopeApis.js +1 -1
- package/dist/features/LearningManagement/components/CreateLearningSetModal.js +1 -1
- package/dist/features/LearningManagement/components/CreateRuleSetLegacyModal.js +2 -0
- package/dist/features/LearningManagement/components/CreateRuleSetLegacyModal.js.map +1 -0
- package/dist/features/LearningManagement/components/InstantLearningModal.js +1 -1
- package/dist/features/LearningManagement/components/ScopeSkeletonLoader.js +2 -0
- package/dist/features/LearningManagement/components/ScopeSkeletonLoader.js.map +1 -0
- package/dist/features/LearningManagement/components/ScopeTree/TreeNode.js +1 -1
- package/dist/features/LearningManagement/components/ScopeTree/TreeSidebar.js +1 -1
- package/dist/features/LearningManagement/components/StationOnboarding/StationAutocomplete.js +1 -1
- package/dist/features/LearningManagement/components/StationOnboarding/StationOnboardModal.js +1 -1
- package/dist/features/LearningManagement/components/ToolTip.js +1 -1
- package/dist/features/LearningManagement/queries/useApprovalQueries.js +2 -0
- package/dist/features/LearningManagement/queries/useApprovalQueries.js.map +1 -0
- package/dist/features/LearningManagement/store/useAppSecRolesStore.js +2 -0
- package/dist/features/LearningManagement/store/useAppSecRolesStore.js.map +1 -0
- package/dist/features/LearningManagement/store/useConfigStore.js +1 -1
- package/dist/features/LearningManagement/store/useLearningTemplateStore.js +1 -1
- package/dist/features/LearningManagement/store/usePermissionsStore.js +2 -0
- package/dist/features/LearningManagement/store/usePermissionsStore.js.map +1 -0
- package/dist/features/LearningManagement/styles/ScopeTree.module.css.js +1 -1
- package/dist/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js +2 -0
- package/dist/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.js +2 -0
- package/dist/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.js.map +1 -0
- package/dist/plugins/ValueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +2 -0
- package/dist/types/src/features/IL-OTJ/ILOTJ.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/ILOTJTest.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.d.ts +57 -0
- package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.d.ts.map +1 -0
- package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.d.ts +9 -3
- package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/_components/templates/RuleComparison/RuleComparison.d.ts +41 -6
- package/dist/types/src/features/IL-OTJ/_components/templates/RuleComparison/RuleComparison.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/LearningManagement.d.ts +3 -4
- package/dist/types/src/features/LearningManagement/LearningManagement.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts +1 -0
- package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/RBAC/AccessManagementPanel.d.ts +8 -0
- package/dist/types/src/features/LearningManagement/RBAC/AccessManagementPanel.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RBAC/AccessPanel.d.ts +14 -0
- package/dist/types/src/features/LearningManagement/RBAC/AccessPanel.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RBAC/index.d.ts +4 -0
- package/dist/types/src/features/LearningManagement/RBAC/index.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.d.ts +12 -0
- package/dist/types/src/features/LearningManagement/RuleContent/AddScopeApprovalSearchComponent.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/AddScopeModal.d.ts +15 -0
- package/dist/types/src/features/LearningManagement/RuleContent/AddScopeModal.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/ApprovalActionButton.d.ts +8 -0
- package/dist/types/src/features/LearningManagement/RuleContent/ApprovalActionButton.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/ApprovalLearningDialog.d.ts +17 -0
- package/dist/types/src/features/LearningManagement/RuleContent/ApprovalLearningDialog.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/PendingApprovalChip.d.ts +7 -0
- package/dist/types/src/features/LearningManagement/RuleContent/PendingApprovalChip.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/RenameScopeModal.d.ts +10 -0
- package/dist/types/src/features/LearningManagement/RuleContent/RenameScopeModal.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts +1 -0
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/apis/apiConfig.d.ts +11 -0
- package/dist/types/src/features/LearningManagement/apis/apiConfig.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts +33 -6
- package/dist/types/src/features/LearningManagement/apis/scopeApis.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/CreateLearningSetModal.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/CreateRuleSetLegacyModal.d.ts +10 -0
- package/dist/types/src/features/LearningManagement/components/CreateRuleSetLegacyModal.d.ts.map +1 -0
- 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/features/LearningManagement/components/ScopeSkeletonLoader.d.ts +32 -0
- package/dist/types/src/features/LearningManagement/components/ScopeSkeletonLoader.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/components/ScopeTree/TreeNode.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/ScopeTree/TreeSidebar.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/StationOnboarding/StationAutocomplete.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/StationOnboarding/StationOnboardModal.d.ts +2 -0
- package/dist/types/src/features/LearningManagement/components/StationOnboarding/StationOnboardModal.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/queries/useApprovalQueries.d.ts +11 -0
- package/dist/types/src/features/LearningManagement/queries/useApprovalQueries.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/store/useAppSecRolesStore.d.ts +11 -0
- package/dist/types/src/features/LearningManagement/store/useAppSecRolesStore.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/store/useConfigStore.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/store/useLearningTemplateStore.d.ts +10 -0
- package/dist/types/src/features/LearningManagement/store/useLearningTemplateStore.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/store/usePermissionsStore.d.ts +34 -0
- package/dist/types/src/features/LearningManagement/store/usePermissionsStore.d.ts.map +1 -0
- package/dist/types/src/features/LearningManagement/types.d.ts +6 -4
- package/dist/types/src/features/LearningManagement/types.d.ts.map +1 -1
- package/dist/types/src/plugins/{valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.d.ts → ValueTypes/Category/CategoryTeachMeRenderer.d.ts} +4 -4
- package/dist/types/src/plugins/ValueTypes/Category/CategoryTeachMeRenderer.d.ts.map +1 -0
- package/dist/types/src/plugins/{valueTypes → ValueTypes}/Default/DefaultTeachMeRenderer.d.ts.map +1 -1
- package/dist/types/src/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.d.ts +28 -0
- package/dist/types/src/plugins/ValueTypes/Guidelines/GuidelinesTeachMeRenderer.d.ts.map +1 -0
- package/dist/types/src/plugins/ValueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.d.ts +4 -0
- package/dist/types/src/plugins/ValueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.d.ts.map +1 -0
- package/package.json +8 -6
- package/dist/cjs/plugins/valueTypes/Default/DefaultTeachMeRenderer.js +0 -2
- package/dist/cjs/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +0 -2
- package/dist/plugins/valueTypes/Default/DefaultTeachMeRenderer.js +0 -2
- package/dist/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.js +0 -2
- package/dist/types/src/plugins/valueTypes/RadioTrafficLearning/RadioTrafficLearningRenderer.d.ts.map +0 -1
- /package/dist/cjs/plugins/{valueTypes → ValueTypes}/Default/DefaultTeachMeRenderer.js.map +0 -0
- /package/dist/cjs/plugins/{valueTypes → ValueTypes}/RadioTrafficLearning/RadioTrafficLearningRenderer.js.map +0 -0
- /package/dist/plugins/{valueTypes → ValueTypes}/Default/DefaultTeachMeRenderer.js.map +0 -0
- /package/dist/plugins/{valueTypes → ValueTypes}/RadioTrafficLearning/RadioTrafficLearningRenderer.js.map +0 -0
- /package/dist/types/src/plugins/{valueTypes → ValueTypes}/Default/DefaultTeachMeRenderer.d.ts +0 -0
|
@@ -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,validateSession as M}from"../apis/scopeApis.js";import A from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as I}from"../store/useLearningTemplateStore.js";import S 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 C}from"../../IL-OTJ/_components/templates/TemplatesMap/templatesMap.js";import{extractAndParseWithProperty as N,parseValidationData as E,extractAndParseResponse as x,extractVariantIds as O}from"../../IL-OTJ/helpers/utils.js";import{useCitations as L}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 R from"../store/useAuthStore.js";import{useConfigStore as D}from"../store/useConfigStore.js";import"./ToolTip.js";import"date-fns";import"framer-motion";import"@mui/icons-material/Close";import"@radix-ui/react-tooltip";import"./StationOnboarding/InputField.js";import"../config.js";import"../store/useEnvStore.js";var j=function(){return a("img",{src:A,alt:"Thinking...",width:"20",height:"20"})},V="INITIAL",P="SUCCESS",F="FAILURE",G="IN_PROGRESS",q=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},U=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},J=function(A){var J,H,B,W,K,Y,z=A.isOpen,Q=A.onClose,Z=A.initialScope,$=void 0===Z?"global":Z,X=A.ruleSet,ee=A.editingRule,ne=A.editingTier,te=A.editingVariants,ie=A.focusedVariantIndex,re=A.setFocusedVariantIndex,ae=A.triggerAddVariant,oe=A.triggerFixGaps,le=A.copiedRule,se=A.copiedSourceTier,ue=A.copiedTargetTier,de=A.initialDraftMessage,ce=s({station:$,tiers:["Tier 1"]}),ve=ce[0],_e=ce[1],pe=s(V),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),Se=Ie[0],ke=Ie[1],Ce=u(null),Ne=s(!1),Ee=Ne[0],xe=Ne[1],Oe=u(!1),Le=I().tiers,Re=l.useRef(new Set),De=s(null);De[0];var je=De[1],Ve=s(null);Ve[0];var Pe=Ve[1],Fe=s(null);Fe[0];var Ge=Fe[1],qe=u(new Map),Ue=u(""),Je=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),Sn=In[0],kn=In[1],Cn=s(null),Nn=Cn[0],En=Cn[1],xn=u(null),On=u(null),Ln=u(null),Rn=u({}),Dn=u([]),jn=u([]),Vn=u({}),Pn=D(),Fn=Pn.configuration,Gn=Pn.ilLabels;d(function(){Mn||kn(null)},[Mn]),d(function(){var e;if(z&&ee){xn.current=ee.ruleId;var n=null===(e=null==te?void 0:te[ie||0])||void 0===e?void 0:e.variantId;En(n||null)}},[z,ee,te,ie]),d(function(){z&&_e(function(n){return e(e({},n),{station:$})})},[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(!z)return hr(),void(gn.current=!1);if(!gn.current){var t=te,i=t&&t.length>0,r=null!=ee;if(i||r){if((null==ee?void 0:ee.ruleTitle)&&$n(ee.ruleTitle),ne&&(_e(function(n){return e(e({},n),{tiers:[ne]})}),On.current=ne.toLowerCase().replace(/ /g,"_")),i){var a=(null==ne?void 0:ne.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[ie||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==ee?void 0:ee.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==ee?void 0:ee.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:U(e.variantType||e.variant_type)})}),Hn(new Map([[a,f]])),rt(o),lt(l),dt(s)}else if(r&&ee){var g=ee.ruleDesc;if(g&&rt(new Map([["tier_1",new Map([[0,g]])]])),ee.whenToApply){var m=ee.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(ee.whenNotToApply){var w=ee.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(le&&se&&ue){$n(le.ruleTitle||""),_e(function(n){return e(e({},n),{tiers:[ue]})}),On.current=ue.toLowerCase().replace(/ /g,"_");var y=se.toLowerCase().replace(/ /g,"_"),h=le.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:le.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[se],scheduling_config:r||{},variant_id:e.variantId,question_id:le.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:U(e.variantType||e.variant_type)})}),Hn(new Map([[y,I]]))}}},[z,ee,te,ne,le,se,ue]),d(function(){if(z){if(console.log("[Accordion Init] editingTier:",ne,"focusedVariantIndex:",ie),ne&&_e(function(n){return e(e({},n),{tiers:[ne]})}),vn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void Ct(void 0);if(ae){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),Ct(void 0);var n=((null==ne?void 0:ne.toLowerCase().replace(/ /g,"_"))||"tier_1").replace(/_/g," ");xt("I want to add a new variant to ".concat(n))}else null!=ie?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(ie," (from VariantCard)")),Ct(ie),$t(function(e){return e+1})):(ee||te&&te.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)},[z,ne,ie,ee,te,ae,vn]),d(function(){z&&oe&&ee&&null!==ie&&xt("I want to fix the gaps")},[z,oe,ee,ie]);var qn={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},Un=s(new Map([["tier_1",new Map([[0,qn]])],["tier_2",new Map([[0,qn]])]])),Jn=Un[0],Hn=Un[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],St=s(void 0),kt=St[0],Ct=St[1],Nt=s(""),Et=Nt[0],xt=Nt[1],Ot=s(null),Lt=Ot[0],Rt=Ot[1],Dt=s([]),jt=Dt[0],Vt=Dt[1],Pt=s([]),Ft=Pt[0],Gt=Pt[1],qt=s({}),Ut=qt[0],Jt=qt[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:S.toastWarning,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(_,{className:S.iconWarning}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleWarning)},{children:"Parsing Issue"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.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],Si=Ai[1],ki=s(""),Ci=ki[0],Ni=ki[1],Ei=s(!0),xi=Ei[0],Oi=Ei[1],Li=s(!1),Ri=Li[0],Di=Li[1],ji=s(!1),Vi=ji[0],Pi=ji[1],Fi=s(""),Gi=Fi[0],qi=Fi[1],Ui=s(""),Ji=Ui[0],Hi=Ui[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=R.getState().user,rr=L(),ar=rr.dispatch,or=rr.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",vt)},[vt]),d(function(){console.log("isCloseModal AI Response updated:",xi)},[xi]),d(function(){!1===vi?(Mi(!1),qi(""),Hi("")):(ke(!1),Ae(""))},[vi]),d(function(){null!=kt&&te&&!te[kt]&&Qi(null)},[kt,te]),d(function(){if(Ee&&!Oe.current){Oe.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");xt("Save this Learning"),xe(!1),setTimeout(function(){Oe.current=!1,xt("")},2e3)}},[Ee]);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}),Si(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}),Si(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}),Si(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==re||re(null),Ct(void 0),xt("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))}),Si(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)||qn;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),Ue.current="",Ki(""),Xi(null),Gt([]),_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,qn]])],["tier_2",new Map([[0,qn]])]])),nt(new Map([["tier_1",new Map],["tier_2",new Map]])),zn(""),Ct(0),$t(0),_e({station:$,tiers:["Tier 1"]}),n||Jt({}),nt(new Map([["tier_1",new Map],["tier_2",new Map]])),xt(""),ni({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Si({}),Ni(""),Oi(!0),je(null),Pe(null),gt(new Map),yt([]),yn(!1),Ge(null),fi.current=null,Je.current=!1,pn.current={},bn.current.clear(),xn.current=null,On.current=null,En(null),Ae(""),ge(V),ye(!1),ke(!1),xe(!1),en(null),rn([]),ln(null),dn(null),An(null),Tt(!1),Rt(null),qi(""),Hi(""),Mi(!1),Kn(new Set),Oe.current=!1,qe.current.clear(),Ze.current=0,Qe.current=null,Ln.current=null,gi.current=-1,hn.current=!1,gn.current=!1,ee){ee.ruleTitle&&$n(ee.ruleTitle),ne&&(_e(function(n){return e(e({},n),{tiers:[ne]})}),On.current=ne.toLowerCase().replace(/ /g,"_")),xn.current=ee.ruleId;var i=null===(t=null==te?void 0:te[ie||0])||void 0===t?void 0:t.variantId;if(En(i||null),te&&te.length>0){var r=(null==ne?void 0:ne.toLowerCase().replace(/ /g,"_"))||"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;te.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=te.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:ee.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:ee.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;te.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,_,p,f,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,w=null!==(s=null!==(o=null==g?void 0:g.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==g?void 0:g.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;v.set(n,{order_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},advertiser_rules:{enabled:w>0,global_min_separation_seconds:Math.floor(w/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==g?void 0:g.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==g?void 0:g.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(f=null!==(p=null===(_=null==g?void 0:g.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==p?p:null==g?void 0:g.respect_break_code)&&void 0!==f&&f},is_default_enabled:U(e.variantType||e.variant_type)})}),Hn(new Map([[r,v]])),Ct(null!=ie?ie:0)}}},[ar,$,ee,ne,te,ie]),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=N(t),a=N(t,"general_details");console.log("--- [CARE] Staging Initial Structure ---",r);var o=N(t,"critical_gaps");if(console.log("isCriticalGap",o),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=U(l)?"Default":"variant",r.isDefault=U(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?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,xn.current=null;var v=(jn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===v&&void 0!==kt&&(v=kt),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)&&xn.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)&&xn.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=!(!ee&&!te),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&te&&te.length>0&&(a=te.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==ee?void 0:ee.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!==kt&&(l=kt),-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=E(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;!(!ee&&!te)&&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!==kt&&(a=kt),-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=(ne||"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==te?void 0:te.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!==kt?kt: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&&(Si(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&&(Si({}),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([]),En(null),Ct(0),$t(0),An(null),yn(!1),_n(!1),Vt([]),xn.current=null,$n(""),tr(null),Hn(new Map([["tier_1",new Map([[0,qn]])],["tier_2",new Map([[0,qn]])]])),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=N(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=O(t);Ge(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)&&!te;(null==u?void 0:u.is_valid)?(Si({}),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)||!ee&&!te)return w;console.log("inside edit flow merge");var b=te||[],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,S,k=b[M]||(null==vt?void 0:vt[M]),C=(null==k?void 0:k.tier_id)||(null==k?void 0:k.tierId)||"1",N=(null==ne?void 0:ne.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 E=Ir(A);Sr(N,M,A,E,ot,lt,null==u?void 0:u.conflict_view),mr(N,M,"wta")}if(void 0!==I){var x=Ir(I);Sr(N,M,I,x,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)?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=Ir(S);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!==S&&(r.rule_description=Ir(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&&_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),qi("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()},Sr=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))}}},kr=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(){Et&&!Oe.current&&"save this learning"!==Et.toLowerCase()&&(ke(!1),Ae(""),gi.current=null!=kt?kt:-1)},[Et]),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)&&te)-1!==(l=te.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if(zi&&te&&1===vt.length){var l;-1!==(l=te.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=kr(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)&&(Sr(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),S=(null===(u=ut.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)&&(Sr(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 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=Jn.get(r))||void 0===d?void 0:d.get(o),E=t.variant_type||t.variantType,x=E?U(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(Jt(function(e){return R(e,k)}),O||L){Jt(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,Jn);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)||qn;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}),nt(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=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&&(Si(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=!(!ee&&!te),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(ae&&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==ie||pi.current&&0!==pi.current.length||(f=ie);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&&kt!==f&&(gi.current===f||Je.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=kr(l),d=s?kr(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==X?void 0:X.ruleSetId)||"",value:{scopeName:(null==X?void 0:X.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==Fn?void 0:Fn.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==X?void 0:X.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}}},Er=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},xr=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=U(r);return{label:"variant ".concat(n+1),isDefault:a}},Or=function(e,n){var t=U(e);return{label:"variant ".concat(n+1),isDefault:t}},Lr=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=Jn.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":U(t)?"Default":"Variant"},Rr=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,A,k;return i(this,function(i){switch(i.label){case 0:t=Cr(ve.tiers),l=Ze.current,s=Er(et,Ut,Jn,l),i.label=1;case 1:return i.trys.push([1,3,,4]),ge(G),Ae(""),u=Nr(s),d=m(),c=[],v=[],p=(vt||[])[l]||{},console.log("originalItem check :",p,l),ve.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=it.get(M))||void 0===r?void 0:r.get(l))||"",I=(null===(a=ot.get(M))||void 0===a?void 0:a.get(l))||[],S=(null===(o=ut.get(M))||void 0===o?void 0:o.get(l))||[],k={status:"approved",metadata:e(e({userName:null!==(s=null==ir?void 0:ir.firstname)&&void 0!==s?s:"",userEmailId:null!==(_=null==ir?void 0:ir.email)&&void 0!==_?_:"",llm:Fn.MODEL,isVariantFlow:!0},u&&{config:e({master_name:Fn.CONFIG_MASTER_NAME},u)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d,variant:Ir(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:Fn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==X?void 0:X.ruleSetId)||"",value:{scopeName:(null==X?void 0:X.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Fn.CUSTOM_SCOPE_GROUP_NAME,description:(null==X?void 0:X.ruleSetDesc)||""}},overriden:!1,isDefault:null===(w=null===(g=null===(f=Jn.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:Fn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(h=Le.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(ve.station||$,"RuleSet"),description:null},categories:[{id:null,value:Fn.CATEGORY,description:Fn.CATEGORY}],originalQuestion:Zn,questionId:n.get(M)||null,variantType:Lr(M,l,p.variant_type||p.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==ir?void 0:ir.email)&&void 0!==b?b:"",instantLearningType:Fn.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==Lt?void 0:Lt.is_user_accepted_risk)},isAgentsFeedback:!0})};c.push(y(k,Fn.ASSISTANT_NAME))}),[4,Promise.all(c)];case 2:return g=i.sent(),xe(!1),console.log("✅ All feedback published:",g),ge(P),ye(!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)}}),I.getState().setCreatedVariantInfo(Array.from(w.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(M=mi.current)||void 0===M||M.show({severity:"success",sticky:!1,life:6e3,className:S.toastSuccess,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(f,{className:S.iconSuccess}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),Ce.current=setTimeout(function(){xi||o?(console.log("Closing modal after save success",{isCloseModal:xi,forceClose:o}),ea()):hr(!0)},3e3),[3,4];case 3:return h=i.sent(),console.error("❌ Error publishing feedback:",h),xe(!1),ge(F),ke(!0),b=(null===(A=null==h?void 0:h.response)||void 0===A?void 0:A.data)||{},console.log("errorData: ",b),(T="Variant already exists"===(null==b?void 0:b.message))||409===(null==h?void 0:h.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==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=mi.current)||void 0===k||k.show({severity:"error",sticky:!1,className:S.toastError,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(_,{className:S.iconError}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.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]}})})},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,A,k,C,N,E,x,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:t=I.getState().tiers,o=Er(et,Ut,Jn),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(G),Ae(""),v=(c=te||[]).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=[],A=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,I,S,k,C,N,E,x,O,L,R,D,j,V,P,F,G,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 $=Er(et,Ut,Jn,c),ne=Nr($);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:Fn.MODEL,isVariantFlow:!0},ne&&{config:e({master_name:Fn.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:A[0]||{name:Fn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==X?void 0:X.ruleSetId)||"",value:{scopeName:(null==X?void 0:X.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Fn.CUSTOM_SCOPE_GROUP_NAME,description:(null==X?void 0:X.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=Jn.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:Fn.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(ve.station,"RuleSet"),description:null},categories:[{id:null,value:Fn.CATEGORY,description:Fn.CATEGORY}],originalQuestion:Zn,questionId:null==ee?void 0:ee.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:Fn.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(S=null===(I=(vt||[])[c])||void 0===I?void 0:I.is_user_accepted_risk)&&void 0!==S?S:null==Lt?void 0:Lt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",te),T.push(y(te,Fn.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==X?void 0:X.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=Jn.get(i))||void 0===k?void 0:k.get(c))||void 0===C?void 0:C.is_default_enabled)&&void 0!==N?N:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||n,tier_priority:null!==(E=null==r?void 0:r.tier_priority)&&void 0!==E?E:null},scope_id:(null==X?void 0:X.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===(x=(vt||[])[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=(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=q(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===U(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!==(G=null===(F=fe.inventory_rules)||void 0===F?void 0:F.respect_inventory_code)&&void 0!==G?G: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=Jn.get(i))||void 0===K?void 0:K.get(c))||qn,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 k=i.sent(),console.log("✅ All variants updated:",k),ge(P),ye(!0),xe(!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)}}}),I.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:S.toastSuccess,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(f,{className:S.iconSuccess}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.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(F),ke(!0),xe(!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)?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==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===(V=mi.current)||void 0===V||V.show({severity:"error",sticky:!1,className:S.toastError,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(_,{className:S.iconError}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.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]}})})},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,A,k,C,N,E,x,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:n=I.getState().tiers,t=Er(et,Ut,Jn),o=Nr(t),i.label=1;case 1:return i.trys.push([1,9,,10]),ge(G),Ae(""),0===(l=Array.isArray(vt)?vt:[]).length?(console.warn("No variants found to save."),ge(F),[2]):(s=l.filter(function(e){return e.is_new_variant}),u=l.filter(function(e){return!e.is_new_variant&&(null==e?void 0:e.variant_id)}),console.log("[saveLoadAndEditVariant] New: ".concat(s.length,", Existing: ").concat(u.length)),d=u.length>0?null===(R=u.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===R?void 0:R.link_id:null,c=[],v=[],p=[],g=[],w=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,S,k,C,N,E,x,O,L,R,D,j,V,P,F,G,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=Er(et,Ut,Jn,l),Z=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:Fn.MODEL,isVariantFlow:!0},Z&&{config:e({master_name:Fn.CONFIG_MASTER_NAME},Z)}),{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:Fn.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==X?void 0:X.ruleSetId)||"",value:{scopeName:(null==X?void 0:X.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Fn.CUSTOM_SCOPE_GROUP_NAME,description:(null==X?void 0:X.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(T=null===(b=null===(y=Jn.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==T?T:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:Fn.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||$,"RuleSet"),description:null},categories:[{id:null,value:Fn.CATEGORY,description:Fn.CATEGORY}],originalQuestion:Zn,questionId:xn.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:Fn.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==X?void 0:X.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=Jn.get(i))||void 0===I?void 0:I.get(l))||void 0===S?void 0:S.is_default_enabled)&&void 0!==k?k:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||t,tier_priority:null!==(C=null==r?void 0:r.tier_priority)&&void 0!==C?C:null},scope_id:(null==X?void 0:X.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===(E=(vt||[])[l])||void 0===E?void 0:E.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=q(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===U(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===(G=_e.break_code_rules)||void 0===G?void 0:G.respect_break_code)&&void 0!==J?J:_e.respect_break_code)&&void 0!==H&&H,we=(null===(B=Jn.get(i))||void 0===B?void 0:B.get(l))||qn,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,A=v,i.label=3;case 3:if(!(M<A.length))return[3,8];k=A[M],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(k.payload,Fn.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)}}),I.getState().setCreatedVariantInfo(Array.from(E.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),ge(P),ye(!0),xe(!1),Je.current=!1,null===(D=mi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:S.toastSuccess,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(f,{className:S.iconSuccess}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ce.current=setTimeout(function(){ea()},3e3),[3,10];case 9:return x=i.sent(),console.error("❌ Error updating variant:",x),ge(F),ke(!0),xe(!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)?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===(V=mi.current)||void 0===V||V.show({severity:"error",sticky:!1,className:S.toastError,content:r("div",e({className:S.toastContent},{children:[r("div",e({className:S.toastHeaderLeft},{children:[a(_,{className:S.iconError}),a("span",e({className:"".concat(S.toastTitle," ").concat(S.toastTitleError)},{children:"Error"}))]})),a("p",e({className:"".concat(S.toastMessage," ").concat(S.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]}})})},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),ee||te?Dr():!0===Je.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(G),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:Fn.ORGANIZATION_NAME,scope_id:(null==X?void 0:X.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(e),[3,6];case 5:return o=u.sent(),l=new Map,ve.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Rr(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Ri,vi]);var Pr=(null===(H=(null===(J=null==ve?void 0:ve.tiers)||void 0===J?void 0:J[0])||ne||"Tier 1")||void 0===H?void 0:H.toLowerCase().replace(/ /g,"_"))||"tier_1",Fr=null!==(B=null!=kt?kt:ie)&&void 0!==B?B:0,Gr=null!=kt,qr=Gr?null==vt?void 0:vt[Fr]:null,Ur=vt&&(null==vt?void 0:vt.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Ft.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&jt.includes(e.variant_id))})),Jr=(null==qr?void 0:qr.new_variant_id)&&Ft.includes(qr.new_variant_id)?qr.new_variant_id:(null==Ur?void 0:Ur.new_variant_id)&&Ft.includes(Ur.new_variant_id)?Ur.new_variant_id:"",Hr=!(!ee&&!te),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=Jn.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==X?void 0:X.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=Jn.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==te?void 0:te[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==X?void 0:X.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==te?void 0:te[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=Fr),{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=Jn.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 Gr&&ee?(null===(e=null==te?void 0:te[Fr])||void 0===e?void 0:e.variantId)?null:Jr:null}(),edit_variant_id:Nn,rule_id:xn.current,ruleset_id:(null==X?void 0:X.ruleSetId)||"",current_variants_length:ee?Array.isArray(vt)&&vt.length>0?Math.max((null===(W=null==ee?void 0:ee.variants)||void 0===W?void 0:W.length)||0,vt.length):null===(K=null==ee?void 0:ee.variants)||void 0===K?void 0:K.length:void 0,tiers:Le,authToken:(null==ir?void 0:ir.accessToken)||""},Kr=br(wt),Yr={ruleTitle:Zn,scopeData:ve,variantsByTier:Array.from(Jn.keys()).reduce(function(n,t){var i=Jn.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&&!U(d.variant_type))c={label:"",isDefault:!1};else if(te&&te.length>0){c=xr(te,n,"variantType"),console.log("Found matching variant at index",n,":",c);var v=te[n];if(v){if(!c.label){var _=v.variantType||"",p=U(_);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(te),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(wt&&wt.length>0){if(c=xr(wt,n,"variant_type"),console.log("Found matching variant at index",n,":",c),Je.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:U(g)}}console.log("Computed variant data for tier",t,"index",n,":",c);var m=null!==(u=null===(s=i.get(n))||void 0===s?void 0:s.is_default_enabled)&&void 0!==u?u:c.isDefault;console.log("live is default :",m);var w="variant ".concat(l+1),y=r.get(n)||"";return{variantId: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)||qn,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),Si(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={};Jn.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(ne){if(1===ve.tiers.length)return 0;var e=ve.tiers.findIndex(function(e){return e.toLowerCase()===ne.toLowerCase()});return e>=0?e:0}},[ne,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:xt,isAiStreaming:vi,defaultTierOpen:$r,defaultVariantOpen:vn?void 0:kt,autoScrollVariantIndex:vn?void 0:kt,activeVariantAccordionIndex:vn?void 0:kt,setActiveVariantAccordionIndex:function(e){Ct(e),null!=e&&setTimeout(function(){_n(!1)},100)},validationErrors:Ii,activeEditId:Mn,setActiveEditId:An,pendingEditId:Sn,setPendingEditId:kn,conflictReason:Ci,usedFor:ee||te?"Edit":"Create"},Gn),{scrollTrigger:Zt});console.log(kt,"editVariantIndex checking"),d(function(){},[z]),d(function(){if(!vi&&bt&&!!(!ee&&!te)){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),Je.current=!1,Q(),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=Jn.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,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,hn.current&&Ln.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(xn.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",_),En(_),_?(-1!==(p=(vt||[]).findIndex(function(e){return e.is_new_variant}))&&(Mi(!0),qi("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",xn.current),null===xn.current&&(Mi(!0),qi("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),qi("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==X?void 0:X.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),qi(""),null===(u=mi.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(Je.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&&((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,")")),_e({station:$||"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:U(e.variantType||e.variant_type)}),s.set(n,q(e.rule_description||""));var _=e.wta?e.wta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,_);var p=e.wnta?e.wnta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,p)}),{transformedVariants:o,tierConfigMap:l,tierDescMap:s,tierWtaMap:u,tierWntaMap:d}}(y,h,M,I,t,_),N=C.transformedVariants,E=C.tierConfigMap,x=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),xn.current=t,En(_),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,E),n}),rt(function(e){var n=new Map(e);return n.set(M,x),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}),Si({}),[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),qi(""),Hi(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&xn.current&&Nn?(console.log("inside edit variant flow",xn.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)&&xn.current&&!Nn?(console.log("inside add new variant flow",xn.current,Nn),Mi(!0),qi("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),qi(""),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]}})})}console.log("RuleSet in render",X);var ia;return r(o,{children:[a(g,{ref:mi}),a(k,{open:z,chatAssistantName:Fn.ASSISTANT_NAME,organizationName:Fn.ORGANIZATION_NAME,baseUrl:Fn.BASE_URL,baseWebsocketUrl:Fn.BASE_WEBSOCKET_URL,closeFunction:ea,ThinkingBulbIconComponent:a(j,{}),customSections:a(o,{}),customMetaData:Wr,chatTitle:ee?Fn.CHAT_TITLE_EDIT.replace("<scope>",(null==X?void 0:X.ruleSetName)||""):Fn.CHAT_TITLE.replace("<scope>",(null==X?void 0:X.ruleSetName)||""),formTitle:Fn.FORM_TITLE,showSavedMessage:!1,savedMessage:be,isError:Se,errorMessage:Me,isSaving:Ee,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 Si(n);xe(!0),ke(!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?(Si(e),[2]):(console.log("✅ Bypass Save: Initiated"),ee||te?[4,Dr()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==Je.current?[3,4]:[4,jr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),ge(G),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:Fn.ORGANIZATION_NAME,scope_id:(null==X?void 0:X.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(F),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:Et,template:C.CreateRule,isLoading:fe===G,templateProps:{state:Yr,handlers:zr,uiState:Xr},setSendMessageInChat:xt,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})})||Jn.size>0||et.size>0},initialChatMessage:ee?(ia=ee.ruleTitle||"this rule",null===(Y=null==te?void 0:te[null!=ie?ie:0])||void 0===Y||Y.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>')):Fn.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(fe===P||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=Jn.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!(!Jn||0===Jn.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:ee?"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:Gi,subText:Ji,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:Fn.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(),kn(Mn)))},isGlobalEditActive:null!==Mn,initialDraftMessage:le?de:"",socketTimeOutInMilliSeconds:Fn.SOCKET_TIMEOUT,onValidateSession:function(e){return t(void 0,void 0,void 0,function(){var n,t;return i(this,function(i){switch(i.label){case 0:if(n=null==X?void 0:X.ruleSetId,console.log("Validating session for scope_id:",n,"sessionStartTime:",e),!n)return console.warn("No scope_id found for session validation."),[2,!1];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,M({scope_id:n,session_start_time:e})];case 2:return[2,i.sent()];case 3:return t=i.sent(),console.error("Session validation failed",t),[2,!1];case 4:return[2]}})})}})]})};export{J as default,q as filterAgentText};
|
|
1
|
+
import{__assign as e,__spreadArray as n,__awaiter as t,__generator as i}from"tslib";import{jsxs as r,jsx as a,Fragment as o}from"react/jsx-runtime";import l,{useState as s,useRef as u,useEffect as d,useCallback as c,useMemo as _}from"react";import{AlertTriangle as v,Loader as p,Check as f}from"lucide-react";import{Toast as g}from"primereact/toast";import{v4 as m}from"uuid";import{saveInstantLearningQuestion as w,publishFeedback as y,updateVariant as h,fetchRulesByQuestionId as b,submitChatFeedback as A}from"../apis/scopeApis.js";import T from"../public/ThinkingBulbIcon.gif.js";import{useLearningTemplateStore as M}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"../../IL-OTJ/_components/templates/RuleComparison/RuleComparison.js";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{IL_CONFIG_CONSTANTS as D}from"../config.js";import"@radix-ui/react-tooltip";import"./StationOnboarding/InputField.js";import"../store/useEnvStore.js";import"react-router-dom";var j=function(){return a("img",{src:T,alt:"Thinking...",width:"20",height:"20"})},V="INITIAL",P="SUCCESS",G="FAILURE",F="IN_PROGRESS",q=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},U=function(e){if(!e)return!1;var n=e.toLowerCase().trim();return"default"===n||"default_variant"===n},J=function(e){return e.toLowerCase().replace(/ /g,"_").replace(/tier(\d+)/i,"tier_$1")},H=function(T){var H,B,W,K,Y,z,Q=T.isOpen,Z=T.onClose,$=T.initialScope,X=void 0===$?"global":$,ee=T.ruleSet,ne=T.editingRule,te=T.editingTier,ie=T.editingVariants,re=T.focusedVariantIndex,ae=T.setFocusedVariantIndex,oe=T.triggerAddVariant,le=T.triggerFixGaps,se=T.copiedRule,ue=T.copiedSourceTier,de=T.copiedTargetTier,ce=T.initialDraftMessage,_e=T.initialChatMessage,ve=T.applicationIntegrationId;T.modeId;var pe=s({station:X,tiers:["Tier 1"]}),fe=pe[0],ge=pe[1],me=s(V),we=me[0],ye=me[1],he=s(!1),be=he[0],Ae=he[1],Te=s("Thank you teacher for teaching me, your rule has been saved successfully."),Me=Te[0];Te[1];var Ie=s(""),ke=Ie[0],Se=Ie[1],Ce=s(!1),Ne=Ce[0],xe=Ce[1],Ee=u(null),Oe=s(!1),Le=Oe[0],Re=Oe[1],De=u(!1),je=M().tiers,Ve=l.useRef(new Set),Pe=s(null);Pe[0];var Ge=Pe[1],Fe=s(null);Fe[0];var qe=Fe[1],Ue=s(null);Ue[0];var Je=Ue[1],He=u(new Map),Be=u(""),We=u(!1),Ke=s(0),Ye=Ke[0],ze=Ke[1],Qe=s(!1),Ze=Qe[0],$e=Qe[1],Xe=u(null),en=u(0),nn=s(null),tn=nn[0],rn=nn[1],an=s([]),on=an[0],ln=an[1],sn=s(null),un=sn[0],dn=sn[1],cn=s(null),_n=cn[0],vn=cn[1],pn=s(!1),fn=pn[0],gn=pn[1],mn=u({}),wn=u([]),yn=u(!1),hn=s(!1),bn=hn[0],An=hn[1],Tn=u(!1),Mn=u(new Set),In=s(null),kn=In[0],Sn=In[1],Cn=s(null),Nn=Cn[0],xn=Cn[1],En=s(null),On=En[0],Ln=En[1],Rn=u(null),Dn=u(null),jn=u(null),Vn=u({}),Pn=u([]),Gn=u([]),Fn=u({}),qn=R(),Un=qn.configuration,Jn=qn.ilLabels;d(function(){kn||xn(null)},[kn]),d(function(){var e;if(Q&&ne){Rn.current=ne.ruleId;var n=null===(e=null==ie?void 0:ie[re||0])||void 0===e?void 0:e.variantId;Ln(n||null)}},[Q,ne,ie,re]),d(function(){Q&&ge(function(n){return e(e({},n),{station:X})})},[Q,X]),d(function(){console.log("triggered",On),console.log(ft,"structuredAIResponse"),gt(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==On&&n.new_variant_id!==On})}):n}),At(function(n){return Array.isArray(n)?n.map(function(n){return e(e({},n),{is_readOnly:n.variant_id!==On&&n.new_variant_id!==On})}):n})},[On]),d(function(){var n;if(!Q)return Tr(),void(yn.current=!1);if(!yn.current){var t=ie,i=t&&t.length>0,r=null!=ne;if(i||r){if((null==ne?void 0:ne.ruleTitle)&&nt(ne.ruleTitle),te&&(ge(function(n){return e(e({},n),{tiers:[te]})}),Dn.current=te.toLowerCase().replace(/ /g,"_")),i){var a=te?J(te):"tier_1",o=new Map,l=new Map,s=new Map,u=new Map,d=new Map,c=new Map,_=[];t.forEach(function(e,n){u.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];c.set(n,i),_.push(e.variantId||e.variant_id||"")}),o.set(a,u),l.set(a,d),s.set(a,c);var v=null===(n=null==t?void 0:t[re||0])||void 0===n?void 0:n.variantId,p=t.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:(null==ne?void 0:ne.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[a],scheduling_config:r||{},variant_id:e.variantId,question_id:(null==ne?void 0:ne.ruleId)||"",tier_id:a.replace("tier_",""),is_readOnly:e.variantId!==v,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});gt(p),gt(p),At(p),yt(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!==(v=null===(_=null==g?void 0:g.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==v?v:null==g?void 0:g.respect_break_code)&&void 0!==p&&p},is_default_enabled:U(e.variantType||e.variant_type)})}),Kn(new Map([[a,f]])),lt(o),dt(l),vt(s)}else if(r&&ne){var g=ne.ruleDesc;if(g&<(new Map([["tier_1",new Map([[0,g]])]])),ne.whenToApply){var m=ne.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wta-".concat(n),text:e,reasoning:""}});dt(new Map([["tier_1",new Map([[0,m]])]]))}if(ne.whenNotToApply){var w=ne.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,n){return{id:"edit-wnta-".concat(n),text:e,reasoning:""}});vt(new Map([["tier_1",new Map([[0,w]])]]))}}}else if(se&&ue&&de){nt(se.ruleTitle||""),ge(function(n){return e(e({},n),{tiers:[de]})}),Dn.current=J(de);var y=J(ue),h=se.variants||[],b=(o=new Map,l=new Map,s=new Map,new Map),A=new Map,T=new Map;h.forEach(function(e,n){b.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e,t){return{id:"copy-wta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];A.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e,t){return{id:"copy-wnta-".concat(n,"-").concat(t),text:e.trim(),reasoning:""}}):[];T.set(n,i)}),o.set(y,b),l.set(y,A),s.set(y,T),lt(o),dt(l),vt(s);var M=h.map(function(e,n){var t,i,r=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config;return{variant_type:e.variantType||"variant",title:se.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[ue],scheduling_config:r||{},variant_id:e.variantId,question_id:se.ruleId||"",tier_id:y.replace("tier_",""),is_readOnly:!0,link_id:e.link_id||"",is_enabled:null===(i=e.is_enabled)||void 0===i||i,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"copy"}});gt(M),At(M),yt(function(e){var n=new Map(e);return n.set(y,JSON.parse(JSON.stringify(M))),n});var I=new Map;h.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,_,v,p,f=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,g=null!==(a=null!==(i=null==f?void 0:f.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==f?void 0:f.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,m=null!==(s=null!==(o=null==f?void 0:f.advertiser_global_min_separation_seconds)&&void 0!==o?o:null===(l=null==f?void 0:f.advertiser_rules)||void 0===l?void 0:l.global_min_separation_seconds)&&void 0!==s?s:0;I.set(n,{order_rules:{enabled:g>0,global_min_separation_seconds:Math.floor(g/60)},advertiser_rules:{enabled:m>0,global_min_separation_seconds:Math.floor(m/60)},inventory_rules:{respect_inventory_code:null!==(c=null!==(d=null===(u=null==f?void 0:f.inventory_rules)||void 0===u?void 0:u.respect_inventory_code)&&void 0!==d?d:null==f?void 0:f.respect_inventory_code)&&void 0!==c&&c},break_code_rules:{respect_break_code:null!==(p=null!==(v=null===(_=null==f?void 0:f.break_code_rules)||void 0===_?void 0:_.respect_break_code)&&void 0!==v?v:null==f?void 0:f.respect_break_code)&&void 0!==p&&p},is_default_enabled:U(e.variantType||e.variant_type)})}),Kn(new Map([[y,I]]))}}},[Q,ne,ie,te,se,ue,de]),d(function(){if(Q){if(console.log("[Accordion Init] editingTier:",te,"focusedVariantIndex:",re),te&&ge(function(n){return e(e({},n),{tiers:[te]})}),fn)return console.log("[Accordion] isAddingNewVariant mode — closing all variant accordions"),void Et(void 0);if(oe){console.log("[Accordion] triggerAddVariant mode — not opening any variant on RHS"),Et(void 0);var n=(te?J(te):"tier_1").replace(/_/g," ");Rt("I want to add a new variant to ".concat(n))}else null!=re?(console.log("[Accordion] Opening SPECIFIC variant index ".concat(re," (from VariantCard)")),Et(re),ni(function(e){return e+1})):(ne||ie&&ie.length>0)&&(console.log("[Accordion] Opening DEFAULT/1st variant (index 0) for RuleHeader edit"),Et(0),ni(function(e){return e+1}))}else Et(void 0)},[Q,te,re,ne,ie,oe,fn]),d(function(){Q&&le&&ne&&null!==re&&Rt("I want to fix the gaps")},[Q,le,ne,re]);var Hn={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},Bn=s(new Map([["tier_1",new Map([[0,Hn]])],["tier_2",new Map([[0,Hn]])]])),Wn=Bn[0],Kn=Bn[1],Yn=s(new Set([])),zn=Yn[0],Qn=Yn[1],Zn=s("");Zn[0];var $n=Zn[1],Xn=s(""),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(new Map([["tier_1",new Map],["tier_2",new Map]])),_t=ct[0],vt=ct[1],pt=s([]),ft=pt[0],gt=pt[1],mt=s(new Map),wt=mt[0],yt=mt[1],ht=s([]),bt=ht[0],At=ht[1],Tt=s(!1),Mt=Tt[0],It=Tt[1],kt=s([]),St=kt[0],Ct=kt[1],Nt=s(void 0),xt=Nt[0],Et=Nt[1],Ot=s(""),Lt=Ot[0],Rt=Ot[1],Dt=s(null),jt=Dt[0],Vt=Dt[1],Pt=s([]),Gt=Pt[0],Ft=Pt[1],qt=s([]),Ut=qt[0],Jt=qt[1],Ht=s({}),Bt=Ht[0],Wt=Ht[1],Kt=s(new Map),Yt=Kt[0],zt=Kt[1],Qt=s(new Set),Zt=Qt[0],$t=Qt[1],Xt=s(0),ei=Xt[0],ni=Xt[1],ti=s({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),ii=ti[0],ri=ti[1],ai=s([]),oi=ai[0],li=ai[1],si=s(""),ui=si[0],di=si[1],ci=s({}),_i=ci[0],vi=ci[1],pi=s(!1),fi=pi[0],gi=pi[1],mi=u(null),wi=u(null),yi=u(-1),hi=u(null);d(function(){Gn.current=ft},[ft]),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=hi.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(v,{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 bi=s(!1),Ai=bi[0],Ti=bi[1],Mi=s(!1),Ii=Mi[0],ki=Mi[1],Si=s({}),Ci=Si[0],Ni=Si[1],xi=s(""),Ei=xi[0],Oi=xi[1],Li=s(!0),Ri=Li[0],Di=Li[1],ji=s(!1),Vi=ji[0],Pi=ji[1],Gi=s(!1),Fi=Gi[0],qi=Gi[1],Ui=s(""),Ji=Ui[0],Hi=Ui[1],Bi=s(""),Wi=Bi[0],Ki=Bi[1],Yi=s(""),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=s(null),rr=ir[0],ar=ir[1],or=L.getState().user,lr=O(),sr=lr.dispatch,ur=lr.getLatestReasoning;d(function(){console.log("Structured AI Response updated:",ft)},[ft]),d(function(){console.log("isCloseModal AI Response updated:",Ri)},[Ri]),d(function(){!1===fi?(ki(!1),Hi(""),Ki("")):(xe(!1),Se(""))},[fi]),d(function(){null!=xt&&ie&&!ie[xt]&&Xi(null)},[xt,ie]),d(function(){if(Le&&!De.current){De.current=!0,console.log("UseEffect triggered: Sending save message to chat agent");Rt("Save this Learning"),Re(!1),setTimeout(function(){De.current=!1,Rt("")},2e3)}},[Le]);var dr=c(function(e,n){on.some(function(n){return n.id===e})?(qi(!0),dn(e),vn(n),setTimeout(function(){vn(null),dn(null)},6e3)):console.warn("Variant ID ".concat(e," not found in comparison variants."))},[on]),cr=_(function(){var e=Fi&&Ye>0;return console.log("[Loader Debug] showComparison: ".concat(Fi,", activeRequests: ").concat(Ye,", Result: ").concat(e)),e},[Fi,Ye]),_r=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;lt(function(e){var i=new Map(e),r=new Map(i.get(n));return r.set(t,a),i.set(n,r),i}),Ni(function(i){if(i["ruleDescription-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["ruleDescription-".concat(n,"-").concat(t)],r}return i})},[]),vr=c(function(t,i){dt(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}),Ni(function(n){if(n["whenToApply-".concat(t,"-").concat(i)]){var r=e({},n);return delete r["whenToApply-".concat(t,"-").concat(i)],r}return n})},[]),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}),Ni(function(i){if(i["whenToApply-".concat(n,"-").concat(t)]){var r=e({},i);return delete r["whenToApply-".concat(n,"-").concat(t)],r}return i})},[]),gr=c(function(e,t){vt(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})},[]),mr=c(function(e,n,t){vt(function(i){var r=new Map(i),a=new Map(r.get(e)),o=a.get(n)||[];return a.set(n,o.filter(function(e){return e.id!==t})),r.set(e,a),r})},[]),wr=c(function(n,t,i,r){vt(function(a){var o=new Map(a),l=new Map(o.get(n)),s=l.get(t)||[];return l.set(t,s.map(function(n){return String(n.id)===String(i)?e(e({},n),{text:r}):n})),o.set(n,l),o})},[]),yr=c(function(e){var n=e.replace(/_/g," ");gn(!0),null==ae||ae(null),Et(void 0),Rt("I want to add a new variant to ".concat(n))},[]),hr=function(n,t,i){var r="".concat(n,"_").concat(t);console.log("Highlighting ".concat(i," at ").concat(r)),zt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!0,t))),a}),setTimeout(function(){zt(function(n){var t,a=new Map(n),o=a.get(r)||{};return a.set(r,e(e({},o),((t={})[i]=!1,t))),a})},1500)},br=c(function(n,t){ge(function(i){var r;return e(e({},i),((r={})[n]=t,r))}),Ni(function(t){if(t[n]){var i=e({},t);return delete i[n],i}return t})},[]),Ar=c(function(n,t,i,r){rt(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}),Kn(function(a){var o,l,s,u=new Map(a),d=new Map(u.get(n)||new Map),c=d.get(t)||Hn;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(){fi&&(qi(!1),vn(null),dn(null))},[fi]);var Tr=c(function(n){var t;if(void 0===n&&(n=!1),n||(sr({type:"RESET"}),mi.current=null,gt([]),Ct([]),li([]),vi({}),qi(!1),Ve.current.clear()),nt(""),Ft([]),gn(!1),Be.current="",Qi(""),tr(null),Jt([]),ge({station:"",tiers:[]}),ze(0),$e(!1),ar(null),lt(new Map([["tier_1",new Map],["tier_2",new Map]])),dt(new Map([["tier_1",new Map],["tier_2",new Map]])),vt(new Map([["tier_1",new Map],["tier_2",new Map]])),Kn(new Map([["tier_1",new Map([[0,Hn]])],["tier_2",new Map([[0,Hn]])]])),rt(new Map([["tier_1",new Map],["tier_2",new Map]])),$n(""),Et(0),ni(0),ge({station:X,tiers:["Tier 1"]}),n||Wt({}),rt(new Map([["tier_1",new Map],["tier_2",new Map]])),Rt(""),ri({ruleTitle:"",ruleDescription:"",scopeData:"",whenToApply:"",whenNotToApply:"",configData:""}),Ni({}),Oi(""),Di(!0),Ge(null),qe(null),yt(new Map),At([]),An(!1),Je(null),wi.current=null,We.current=!1,mn.current={},Mn.current.clear(),Rn.current=null,Dn.current=null,Ln(null),Se(""),ye(V),Ae(!1),xe(!1),Re(!1),rn(null),ln([]),dn(null),vn(null),Sn(null),It(!1),Vt(null),Hi(""),Ki(""),ki(!1),Qn(new Set),De.current=!1,He.current.clear(),en.current=0,Xe.current=null,jn.current=null,yi.current=-1,Tn.current=!1,yn.current=!1,ne){ne.ruleTitle&&nt(ne.ruleTitle),te&&(ge(function(n){return e(e({},n),{tiers:[te]})}),Dn.current=te.toLowerCase().replace(/ /g,"_")),Rn.current=ne.ruleId;var i=null===(t=null==ie?void 0:ie[re||0])||void 0===t?void 0:t.variantId;if(Ln(i||null),ie&&ie.length>0){var r=te?J(te):"tier_1",a=new Map,o=new Map,l=new Map,s=new Map,u=new Map,d=new Map;ie.forEach(function(e,n){s.set(n,e.description||"");var t=e.whenToApply?e.whenToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,t);var i=e.whenNotToApply?e.whenNotToApply.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,i)}),a.set(r,s),o.set(r,u),l.set(r,d),lt(a),dt(o),vt(l);var c=ie.map(function(e){var n,t,a=null===(n=e.configuration)||void 0===n?void 0:n.scheduling_config;return{variant_type:e.variantType||"variant",title:ne.ruleTitle||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",scope:[r],scheduling_config:a||{},variant_id:e.variantId,question_id:ne.ruleId||"",tier_id:r.replace("tier_",""),is_readOnly:e.variantId!==i,link_id:e.link_id||"",is_enabled:null===(t=e.is_enabled)||void 0===t||t,is_user_accepted_risk:e.is_user_accepted_risk,has_accepted_risk:e.has_accepted_risk,user_accepted_risk_at:e.user_accepted_risk_at,action:"edit"}});gt(c),At(c),yt(function(e){var n=new Map(e);return n.set(r,JSON.parse(JSON.stringify(c))),n});var _=new Map;ie.forEach(function(e,n){var t,i,r,a,o,l,s,u,d,c,v,p,f,g=null===(t=e.configuration)||void 0===t?void 0:t.scheduling_config,m=null!==(a=null!==(i=null==g?void 0:g.order_global_min_separation_seconds)&&void 0!==i?i:null===(r=null==g?void 0:g.order_rules)||void 0===r?void 0:r.global_min_separation_seconds)&&void 0!==a?a:0,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;_.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===(v=null==g?void 0:g.break_code_rules)||void 0===v?void 0:v.respect_break_code)&&void 0!==p?p:null==g?void 0:g.respect_break_code)&&void 0!==f&&f},is_default_enabled:U(e.variantType||e.variant_type)})}),Kn(new Map([[r,_]])),Et(null!=re?re:0)}}},[sr,X,ne,te,ie,re]),Mr=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)},Ir=c(function(){console.log("variantIds",Gt),qi(!0)},[Gt]),kr={"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;yi.current!==r&&(console.log("Opening variant accordion: AI index ".concat(i," → 0-based index ").concat(r)),Et(r),yi.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),$e(!!o),r){if(r.variant_type&&!("is_variant"in r)){var l=null===(i=Cr(r.variant_type||"").toLowerCase().match(/^(default_variant|default|variant)/i))||void 0===i?void 0:i[0];r.variant_type=U(l)?"Default":"variant",r.isDefault=U(l),console.log("parsed.variant_type",r.variant_type)}var s=r.scope&&r.scope.length>0?String(r.scope[0]):null,u=s?Cr(s).toLowerCase().trim().replace(/ /g,"_"):null,d=Boolean(u&&Dn.current!==u);if(d&&u){var c=Dn.current;console.log("[Tier Switch Detected]",Dn.current,"→",u),Dn.current=u,Rn.current=null;var _=(Gn.current||[]).findIndex(function(e){return!0===(null==e?void 0:e.is_new_variant)});-1===_&&void 0!==xt&&(_=xt),c&&-1!==_&&(console.log("[Tier Switch] Stripping draft variant at index ".concat(_," from ").concat(c)),lt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),dt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),vt(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),Kn(function(e){var n=new Map(e),t=new Map(n.get(c)||new Map);return t.delete(_),n.set(c,t),n}),gt(function(t){if(!Array.isArray(t))return t;var i=n([],t,!0);return i[_]&&(i[_]=e(e({},i[_]),{scope:[u],tier_id:u.replace("tier_","")})),Gn.current=i,i})),yi.current=-1;var v=u.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()});ge(function(n){return e(e({},n),{tiers:[v]})})}Vt(r),Ge({Updated_Fields_Response:r,General_Response:a}),(null==a?void 0:a.variant_id)&&"new_variant_id"===(null==a?void 0:a.variant_id)&&(a.variant_id=null),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&oa(a,r,d),(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&Rn.current&&On?gt(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===On?e(e({},n),r):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===On});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Et(i),ni(function(e){return e+1}),yi.current=i},0),t}):(null==a?void 0:a.is_interpretation_ready)&&(null==a?void 0:a.question_id)&&Rn.current&&!On?gt(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(){Et(a),ni(function(e){return e+1}),yi.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(){Et(o),ni(function(e){return e+1}),yi.current=o},0),i=n(n([],t,!0),[e(e({},r),{is_new_variant:!0})],!1)}}else setTimeout(function(){Et(0),ni(function(e){return e+1}),yi.current=0},0),i=[e(e({},r),{is_new_variant:!0})];return Gn.current=i,i}):(null==a?void 0:a.is_interpretation_ready)&&(gt([r]),setTimeout(function(){Et(0),ni(function(e){return e+1}),yi.current=0},0)),void 0!==r.is_user_accepted_risk&>(function(t){var i=!(!ne&&!ie),a=Array.isArray(t)?n([],t,!0):[];if(i&&0===a.length&&ie&&ie.length>0&&(a=ie.map(function(e,n){var t;return{variant_type:e.variantType||"variant ".concat(n+1),title:(null==ne?void 0:ne.ruleTitle)||"",rule_description:e.description||"",wta:e.whenToApply||"",wnta:e.whenNotToApply||"",is_valid:!0,is_readOnly:e.variantId!==On,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=$i||nr,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!==xt&&(l=xt),-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(qe(o),console.log("--- [RHS] Updating Staged Logic ---"),console.log("parsed data from RHS Validation",o),o){Vt(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(ft)){var r=$i||nr,a=-1;!(!ne&&!ie)&&r&&(a=ft.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!==xt&&(a=xt),-1!==a&&(i=ft[a])}t=i?e({},i):{wta:"",wnta:""}}return e(e({},t),{wta:t.wta,wnta:t.wnta,is_valid:o.is_valid,conflictingConditions:o.conflictingConditions||[],conflictMarkdown:{},conflict_view:o.conflict_view||{}})});var l=(te||"Tier 1").toLowerCase().replace(/ /g,"_"),s=function(){var e,n=Gn.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(On)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===On||(null==e?void 0:e.new_variant_id)===On})))return t;if($i)if(-1!==(t=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===$i||(null==e?void 0:e.new_variant_id)===$i})))return t;var r=null!==(e=null==ie?void 0:ie.length)&&void 0!==e?e:0;if(n.length>r){var a=n.length-1;return console.log("[RHS] Resolved via length diff (new variant appended):",a),a}}var o=void 0!==xt?xt: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&&(Ni(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}),Oi("")),o.conflict_view&&((null===(r=o.conflict_view.wta)||void 0===r?void 0:r.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.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&&vt(function(t){var i=new Map(t),r=new Map(i.get(l)||new Map),a=n([],r.get(s)||[],!0);return o.conflict_view.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&&(Ni({}),Oi(""),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}),vt(function(n){var t=new Map(n),i=new Map(t.get(l)||new Map),r=i.get(s)||[];return i.set(s,r.map(function(n){return e(e({},n),{conflict:void 0})})),t.set(l,i),t}))}},"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)&&oa(n,null),"save"===(null==n?void 0:n.action)&&(null==n?void 0:n.is_save)&&(Di(!0),Pi(!0)),"discard_rule"===(null==n?void 0:n.action))&&(gt([{variant_id:void 0,rule_description:"",wta:"",wnta:"",variant_type:"variant"}]),At([]),Ln(null),Et(0),ni(0),Sn(null),An(!1),gn(!1),Ft([]),Rn.current=null,nt(""),ar(null),Kn(new Map([["tier_1",new Map([[0,Hn]])],["tier_2",new Map([[0,Hn]])]])),lt(new Map([["tier_1",new Map],["tier_2",new Map]])),dt(new Map([["tier_1",new Map],["tier_2",new Map]])),vt(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),dn(l))}catch(e){console.error("Failed to parse rule_validation_card JSON",e)}}var s=C(t,"critical_gaps");console.log("isCriticalGap",s),$e(!!s);var u="string"==typeof t?x(t):t;console.log("parsed data from Validation Agent",u);var d=E(t);Je(u);var c=!!(null==u?void 0:u.is_variant),_=void 0===(null==u?void 0:u.close_modal)||!!(null==u?void 0:u.close_modal),v=void 0!==(null==u?void 0:u.is_save)&&!!(null==u?void 0:u.is_save);Di(_),Pi(v);var p=null==u?void 0:u.action,f="string"==typeof(null==u?void 0:u.edit_variant_id)&&u.edit_variant_id.trim()?u.edit_variant_id:"string"==typeof(null==u?void 0:u.set_variant_id)&&u.set_variant_id.trim()?u.set_variant_id:null,g="variant"===p&&c;if((null==u?void 0:u.edit_variant_id)&&!g&&Xi(u.edit_variant_id),"edit"!==p&&"edit_current_rule"!==p||!f||tr(f),g&&(Xi(null),tr(null)),"discard"===p)return console.log("Action 'discard' received: Resetting UI state but preserving chat."),yn.current=!0,Tr(!0),gt([]),mi.current=null,void(wi.current=null);Qi(p);var m=null==u?void 0:u.new_variant_id,w="edit"===(null==u?void 0:u.action)&&(null==u?void 0:u.set_variant_id)&&!ie;(null==u?void 0:u.is_valid)?(Ni({}),Vt(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(ft)&&h&&(y=h,ft.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===y||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===y||(null==e?void 0:e.id)&&e.id===y})),"edit"!==(null==u?void 0:u.action)||!ne&&!ie)return w;console.log("inside edit flow merge");var b=ie||[],A=f,T=A?b.findIndex(function(e){return e.variantId===A||e.variant_id&&e.variant_id===A||e.id&&e.id===A}):-1;if(-1===T&&(null==u?void 0:u.set_variant_id)&&(T=b.findIndex(function(e){return e.variantId===u.set_variant_id||e.variant_id&&e.variant_id===u.set_variant_id||e.id&&e.id===u.set_variant_id})),-1===T&&A&&Array.isArray(ft)&&(T=ft.findIndex(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===A||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===A||(null==e?void 0:e.id)&&e.id===A})),-1!==T){var M,I,k,S=b[T]||(null==ft?void 0:ft[T]),C=(null==S?void 0:S.tier_id)||(null==S?void 0:S.tierId)||"1",N=(null==te?void 0:te.toLowerCase().replace(/ /g,"_"))||"tier_".concat(C);if(yi.current!==T&&(Et(T),yi.current=T),Array.isArray(null===(l=u.condition_result)||void 0===l?void 0:l.when_to_apply)?M=u.condition_result.when_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wta")&&void 0!==(null==u?void 0:u.wta)?M=null!==(s=null==u?void 0:u.wta)&&void 0!==s?s:"":m(t,"wta")&&void 0!==(null==t?void 0:t.wta)&&(M=null!==(d=null==t?void 0:t.wta)&&void 0!==d?d:""),Array.isArray(null===(c=u.condition_result)||void 0===c?void 0:c.when_not_to_apply)?I=u.condition_result.when_not_to_apply.filter(function(e){return e&&"none"!==e.toLowerCase()}).join("\n"):m(u,"wnta")&&void 0!==(null==u?void 0:u.wnta)?I=null!==(_=null==u?void 0:u.wnta)&&void 0!==_?_:"":m(t,"wnta")&&void 0!==(null==t?void 0:t.wnta)&&(I=null!==(v=null==t?void 0:t.wnta)&&void 0!==v?v:""),void 0!==M){var x=Cr(M);Nr(N,T,M,x,ut,dt,null==u?void 0:u.conflict_view),hr(N,T,"wta")}if(void 0!==I){var E=Cr(I);Nr(N,T,I,E,_t,vt,null==u?void 0:u.conflict_view),hr(N,T,"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=Cr(k);lt(function(e){var n=new Map(e),t=new Map(n.get(N)||new Map);return t.set(T,O),n.set(N,t),n}),hr(N,T,"ruleDescription")}var L=void 0;m(u,"scheduling_config")&&void 0!==(null==u?void 0:u.scheduling_config)?L=null==u?void 0:u.scheduling_config:m(t,"scheduling_config")&&void 0!==(null==t?void 0:t.scheduling_config)&&(L=null==t?void 0:t.scheduling_config),L&&(Kn(function(e){var n,i,r,a,o,l,s=new Map(e),u=new Map(s.get(N)||new Map);return u.set(T,{order_rules:{enabled:!!(null===(n=L.order_rules)||void 0===n?void 0:n.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(i=L.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!(null===(r=L.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor(((null===(a=L.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!(null===(o=L.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!(null===(l=L.break_code_rules)||void 0===l?void 0:l.respect_break_code)},is_default_enabled:"Default"===(null==t?void 0:t.variant_type)||"default_variant"===(null==t?void 0:t.variant_type)||"default"===(null==t?void 0:t.variant_type)}),s.set(N,u),s}),hr(N,T,"order_enabled"),hr(N,T,"advertiser_enabled"),hr(N,T,"respect_inventory_code"),hr(N,T,"respect_break_code")),gt(function(t){if(!Array.isArray(t)||T<0||!t[T])return t;var i=n([],t,!0),r=e({},i[T]);return void 0!==M&&(r.wta=M),void 0!==I&&(r.wnta=I),void 0!==k&&(r.rule_description=Cr(k)),L&&(r.scheduling_config=L),console.log("updated variantxxx",r),i[T]=r,i});var R=null==t?void 0:t.variant_type;R&>(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===A||(null==e?void 0:e.variant_id)&&e.variant_id===(null==u?void 0:u.set_variant_id)||(null==e?void 0:e.variantId)===A});return-1!==r?i[r]=e(e({},i[r]),{variant_type:R}):i[T]=e(e({},i[T]||{}),{variant_type:R,variant_id:A||(null==u?void 0:u.set_variant_id)}),i})}})):console.warn("⚠️ parsed.is_valid is false, not committing to structuredAIResponse"),w||(c?(It(!0),m&&m!==wi.current?(console.log("🚀 New Variant detected (".concat(m,"). Triggering loader.")),ki(!0),Hi("Loading a variant"),console.log("reaching here in new variant flow"),Ki("This may take a moment as we update the rule with the new variant."),wi.current=m):m||console.log("ℹ️ Variant flow detected without specific ID.")):(It(!1),wi.current=null),d&&Ft(d))},"Rule comparison results":function(n){var t=function(n){if("string"!=typeof n)return n;try{var t=Array.from(n.matchAll(/<!--\s*```json\s*([\s\S]*?)\s*```\s*-->/g));if(0===t.length)return JSON.parse(n);var i=t.map(function(e){try{return JSON.parse(e[1].trim())}catch(e){return console.error("Failed to parse JSON block:",e),null}}).filter(function(e){return null!==e});return 1===i.length?i[0]:i.length>1?i.reduce(function(n,t){return e(e({},n),t)},{}):null}catch(e){return console.error("Error extracting JSON:",e),null}}(n);console.log(" LLM Push Comparison Received:",t);var i=t[0].current_rule_details;i&&rn({title:i.rule_title||"",description:i.description||"",scope:i.scope||"",wta:Array.isArray(i.wta)?i.wta.join("\n"):i.wta||"",wnta:Array.isArray(i.wnta)?i.wnta.join("\n"):i.wnta||""});var r=t.map(function(e){var n,t,i=e.variant_rule_details||{},r=e.rule_difference_comparison||{},a=i.when_to_apply||i.wta||"",o=i.when_not_to_apply||i.wnta||"";return{id:(null==i?void 0:i.variant_id)&&i.variant_id||(null==i?void 0:i.id)&&i.id||"fallback-id-".concat(Math.random()),title:i.variant_title||i.rule_title||"",description:i.variant_text||i.description||"",scope:i.scope||"",wta:Array.isArray(a)?a.join("\n"):a,wnta:Array.isArray(o)?o.join("\n"):o,similarity:(null===(n=r.summary)||void 0===n?void 0:n.overall_score)||0,summaryText:(null===(t=r.summary)||void 0===t?void 0:t.overall_summary)||"",analysis:{rule_difference_comparison:r},isLoading:!1}});ln(r)}},Sr=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},Cr=function(e){return"string"!=typeof e?"":e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,"").trim()},Nr=function(t,i,r,a,o,l,s){var u;if(void 0!==r){var d=(o.get(t)||new Map).get(i)||[],c=d.map(function(e){return e.text}).join("\n"),_=(null===(u=d[(null==d?void 0:d.length)-1])||void 0===u?void 0:u.reasoning)||"",v=Sr(r)||"";if(""===r&&d.length>0||a.trim()!==c.trim()||v!==_){var p=""===r?{updatedItems:[],newIds:[]}:function(t,i,r){if(!t.trim())return{updatedItems:n([],i,!0),newIds:[]};var a=t.match(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g)||[],o=t.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,"").replace(/<!--```json[\s\S]*?```-->/g,""),l=[],s=o.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,function(e){return l.push(e),"__CONFLICT_BLOCK_".concat((null==l?void 0:l.length)-1,"__")}).split(/\s*(?:\r?\n|\\+n)\s*/).map(function(e){return e.trim().replace(/^-\s*/,"")}).filter(Boolean),u=new Map(i.map(function(e){return[e.text,e]})),d=[],c=[],_=Array.isArray(null==r?void 0:r.wta)&&t.includes("wta")?r.wta:Array.isArray(null==r?void 0:r.wnta)?r.wnta:[];return s.forEach(function(n,t){var i=n;i.includes("__CONFLICT_BLOCK_")&&(i=i.replace(/__CONFLICT_BLOCK_(\d+)__/g,function(e,n){return l[parseInt(n)]}));var r=a[t]||"",o=i.replace(/<conflicting>[\s\S]*?<\/conflicting>/g,"").trim(),s=null==_?void 0:_.find(function(e){return e.value===o}),v=u.get(i);if(v)c.push(e(e({},v),{reasoning:r||v.reasoning,conflict:s||v.conflict}));else{var p="new-".concat(Date.now(),"-").concat(t);d.push(p),c.push({id:p,text:i,reasoning:r,conflict:s})}}),{updatedItems:c,newIds:d}}(r,d,s),f=p.updatedItems,g=p.newIds;l(function(e){var n=new Map(e),r=new Map(n.get(t)||new Map);return r.set(i,f),n.set(t,r),n}),(null==g?void 0:g.length)>0&&($t(function(e){return new Set(n(n([],Array.from(e),!0),g,!0))}),setTimeout(function(){$t(function(e){var n=new Set(e);return g.forEach(function(e){return n.delete(e)}),n})},1500))}}},xr=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(){Lt&&!De.current&&"save this learning"!==Lt.toLowerCase()&&(xe(!1),Se(""),yi.current=null!=xt?xt:-1)},[Lt]),d(function(){var t,i,r,a,o,l,s,u,d;if(Pn.current=oi,Array.isArray(ft)&&ft.length>0){var c=ui||"local-".concat(Date.now()),_=["ruleTitle","ruleDescription","whenToApply","whenNotToApply","scopeData","configData"],v={},p=mi.current||[];ft.forEach(function(t,i){var r,a;if(t){t.is_readOnly||(en.current=i);var o=i;if((null==t?void 0:t.variant_id)&&ie)-1!==(l=ie.findIndex(function(e){return e.variantId===t.variant_id}))&&(o=l);else if($i&&ie&&1===ft.length){var l;-1!==(l=ie.findIndex(function(e){return e.variantId===$i}))&&(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=xr(u).map(function(e){return e.toLowerCase().replace(/ /g,"_")}),c=d.length>0?d:wn.current.length>0?wn.current:["tier_1"];c.length>0&&(wn.current=c),console.log("prevTierRef.current",wn.current,"targetTiers",c);var f=Cr(t.title);f&&f!==Cr(null==s?void 0:s.title)&&!t.is_readOnly&&function(e,n,t,i,r,a){var o=Cr(i);o&&o!==r&&(hr(e,n,t),a(o))}("global",0,"ruleTitle",t.title,et,nt),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=Cr(t.rule_description),w=(null===(l=ot.get(r))||void 0===l?void 0:l.get(o))||"",y=Cr(w);g&&(m!==y||""===m&&""!==w)&&(lt(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}),hr(r,o,"ruleDescription"));var h=!1===(null==jt?void 0:jt.is_valid),b=Cr(t.wta),A=Cr(null==c?void 0:c.wta),T=(null===(s=ut.get(r))||void 0===s?void 0:s.get(o))||[];!(h&&""===b&&T.length>0)&&void 0!==t.wta&&null!==t.wta&&(b!==A||""===b&&T.length>0||0===T.length&&""!==b)&&(Nr(r,o,t.wta,b,ut,dt,null==jt?void 0:jt.conflict_view),hr(r,o,"wta"));var M=Cr(t.wnta),I=Cr(null==c?void 0:c.wnta),k=(null===(u=_t.get(r))||void 0===u?void 0:u.get(o))||[];if(!(h&&""===M&&k.length>0)&&void 0!==t.wnta&&null!==t.wnta&&(M!==I||""===M&&k.length>0||0===k.length&&""!==M)&&(Nr(r,o,t.wnta,M,_t,vt,null==jt?void 0:jt.conflict_view),hr(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=Wn.get(r))||void 0===d?void 0:d.get(o),x=t.variant_type||t.variantType,E=x?U(x):void 0,O=JSON.stringify(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(Wt(function(e){return R(e,S)}),O||L){Wt(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,Wn);D.forEach(function(e){return hr(r,o,e)}),Qn(function(e){return new Set(e).add("config")}),Kn(function(n){var t,i,a,l,s,u,d=new Map(n),c=new Map(d.get(r)||new Map),_=c.get(o)||Hn;return c.set(o,e(e(e(e(e(e({},_),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}),rt(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||_.forEach(function(e){var n=Sr(j[e]),t="ruleTitle"===e||"scopeData"===e?e:"".concat(e,"_").concat(r);n&&(n!==Vn.current[t]&&(Vn.current[t]=n,Fn.current[t]=!0,v[t]={reasoning:n,associatedCitations:[],tier:r,variantIndex:o}))}),t.conflictingConditions&&(Ni(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}),Qn(function(e){return new Set(n(n([],Array.from(e),!0),["conditions"],!1))}))})}});var f=-1,g=!(!ne&&!ie),m="edit"===zi||"edit_current_rule"===zi,w=function(e,n){return(null==e?void 0:e.variant_id)&&e.variant_id===n||(null==e?void 0:e.new_variant_id)&&e.new_variant_id===n||(null==e?void 0:e.id)&&e.id===n},y=function(e,n){if(!n)return-1;var t=e.find(function(e){return w(e,n)});if(!t)return-1;var i=String((null==t?void 0:t.tier_id)||"");if(!i)return e.findIndex(function(e){return w(e,n)});var r=e.filter(function(e){return String((null==e?void 0:e.tier_id)||"")===i}).findIndex(function(e){return w(e,n)});return-1!==r?r:e.findIndex(function(e){return w(e,n)})};if(g)if(wi.current&&Mt)-1!==(f=ft.findIndex(function(e){return(null==e?void 0:e.new_variant_id)&&e.new_variant_id===wi.current||(null==e?void 0:e.variant_id)&&e.variant_id===wi.current||(null==e?void 0:e.id)&&e.id===wi.current}))&&(wi.current=null);else if($i||nr){var h;(h=$i||nr)&&(f=y(ft,h))}else if(oe&&Array.isArray(ft)&&ft.length>0){for(b=ft.length-1;b>=0;b--)if(ft[b]&&!(null===(i=ft[b])||void 0===i?void 0:i.is_readOnly)){f=b;break}}else null==re||mi.current&&0!==mi.current.length||(f=re);else if((h=$i||nr||wi.current)&&m&&(f=y(ft,h)),!m&&-1===f&&Array.isArray(ft)&&ft.length>0){for(var b=ft.length-1;b>=0;b--)if(ft[b]&&!(null===(t=ft[b])||void 0===t?void 0:t.is_readOnly)){f=b;break}-1===f&&(f=ft.length-1)}-1!==f&&xt!==f&&(yi.current===f||We.current&&!m||(console.log("🎯 Setting active variant accordion to index ".concat(f," (").concat(g?"EDIT":"CREATE"," mode)")),Et(f),yi.current=f));var A=ft[0];if(A){if(A.scope&&JSON.stringify(A.scope)!==JSON.stringify(null===(r=p[0])||void 0===r?void 0:r.scope)&&"copy"!==A.action&&(l=A.scope,s=null===(a=p[0])||void 0===a?void 0:a.scope,u=xr(l),d=s?xr(s):[],ge(function(n){return e(e({},n),{tiers:u})}),u.forEach(function(e){var n=e.trim();d.includes(e)||hr("global",0,"scope_".concat(n))})),A.scope_rule_set&&A.scope_rule_set!==(null===(o=p[0])||void 0===o?void 0:o.scope_rule_set)){var T=A.scope_rule_set.toLowerCase().trim();["global","genre","custom"].includes(T)&&(ge(function(n){return e(e({},n),{station:T})}),hr("global",0,"scope_station"))}A.wtl&&$n(A.wtl)}mi.current=ft.map(function(e){return e?(n=e,"function"==typeof(t=null===globalThis||void 0===globalThis?void 0:globalThis.structuredClone)?t(n):JSON.parse(JSON.stringify(n))):e;var n,t}),Object.keys(v).length>0&&(sr({type:"SAVE_CITATIONS",requestId:c,reasoningMap:v,rawCitations:oi}),function(e){var n=e.requestId,t=e.keys,i=e.newReasoningMap,r=e.getLatestReasoning,a=e.currentCitations;console.group("%c Citation Audit: ".concat(n," "),"background: #5928ed; color: #fff; font-weight: bold;");var o={};t.forEach(function(e){var n=r(e),t=!!i[e],l=t?a:(null==n?void 0:n.associatedCitations)||[];o[e]={Status:t?"NEW ✅":n?"FALLBACK 🔄":"EMPTY ❌",Source:t?"Current Msg":n?"History":"N/A","Reasoning Preview":t?i[e].reasoning:(null==n?void 0:n.reasoning)||"None","Full Citations":l}}),console.table(o),console.groupEnd()}({requestId:c,keys:Object.keys(v),newReasoningMap:v,getLatestReasoning:ur,currentCitations:oi}),ri(function(n){var t=e({},n),i=!1;return Object.keys(v).forEach(function(e){var n=v[e];n.reasoning&&t[e]!==n.reasoning&&(t[e]=n.reasoning,i=!0),n.associatedCitations}),i?t:n}))}},[ft,oi,ui]),d(function(){var t=Object.keys(Fn.current);if(0!==t.length){var i={};t.forEach(function(e){i[e]=n([],oi,!0)}),Fn.current={},vi(function(n){return e(e({},n),i)})}},[oi]);var Er=function(e){return e.map(function(e){var n;return null===(n=e.match(/\d+/))||void 0===n||n[0],e.replace(/\s+/g,"-"),{name:"Custom",parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:(null==Un?void 0:Un.CUSTOM_SCOPE_GROUP_NAME)||"",description:(null==ee?void 0:ee.ruleSetDesc)||""}}})},Or=function(e){var n={};return Object.entries(e).forEach(function(e){var t,i=e[0],r=e[1];if("custom_sep_time_for_entities"===i&&r)n.custom_sep_time_for_entities=r;else if("max_priority_override"===i&&r&&void 0!==r.override_priority_code)n.override_priority_code=r.override_priority_code;else if("advertiser_pair_break_constraint"===i&&r)n.advertiser_pair_break_constraint=r.advertiser_pair_list;else if(r&&"object"==typeof r&&(null===(t=Object.keys(r))||void 0===t?void 0:t.length)>0){var a=i.replace(/_rules$/,""),o=["global_min_separation_seconds","respect_inventory_code","respect_break_code","exemption_advertiser_list","exemption_break_code_list","exemption_priority_code_list","priority_code_list","exemption_product_code_list","condition_advertiser_list","condition_break_code_list","condition_priority_code_list","condition_product_code_list"];Object.entries(r).forEach(function(e){var t=e[0],r=e[1];if(o.includes(t)&&("product_rules"!==i||"global_min_separation_seconds"!==t)){var l="respect_inventory_code"===t||"respect_break_code"===t?t:"".concat(a,"_").concat(t);n[l]=r}})}else if(void 0!==r&&"object"!=typeof r){if("station_guid"===i||"is_default_enabled"===i)return;n[i]=r}}),{config_structure:{scheduling_config:{advertiser_exemption_advertiser_list:"array",advertiser_exemption_break_code_list:"array",advertiser_exemption_priority_code_list:"array",advertiser_exemption_product_code_list:"array",advertiser_global_min_separation_seconds:"int",break_code_exemption_advertiser_list:"array",break_code_exemption_break_code_list:"array",break_code_exemption_priority_code_list:"array",break_code_exemption_product_code_list:"array",custom_sep_time_for_entities:"object",inventory_exemption_advertiser_list:"array",inventory_exemption_break_code_list:"array",inventory_exemption_priority_code_list:"array",inventory_exemption_product_code_list:"array",order_exemption_advertiser_list:"array",order_exemption_break_code_list:"array",order_exemption_priority_code_list:"array",order_exemption_product_code_list:"array",order_global_min_separation_seconds:"int",override_priority_code:"str",product_exemption_advertiser_list:"array",product_exemption_break_code_list:"array",product_exemption_priority_code_list:"array",product_exemption_product_code_list:"array",max_priority_override_priority_code_list:"array",max_priority_override_exemption_advertiser_list:"array",max_priority_override_exemption_break_code_list:"array",max_priority_override_exemption_priority_code_list:"array",max_priority_override_exemption_product_code_list:"array",first_in_break_exemption_advertiser_list:"array",first_in_break_exemption_break_code_list:"array",first_in_break_exemption_priority_code_list:"array",first_in_break_exemption_product_code_list:"array",first_in_break_condition_advertiser_list:"array",first_in_break_condition_break_code_list:"array",first_in_break_condition_priority_code_list:"array",first_in_break_condition_product_code_list:"array",advertiser_pair_break_constraint:"array",respect_break_code:"bool",respect_inventory_code:"bool"}},config_data:{scheduling_config:n}}},Lr=function(n,t,i,r){void 0===r&&(r=0);var a=e({},t||{});return n.forEach(function(n,o){var l=n.get(r);l&&l.forEach(function(n){var l,s=t[n]||{},u=i.get(o),d=null==u?void 0:u.get(r),c=null==d?void 0:d[n];if("order_rules"===n||"advertiser_rules"===n){var _=null!==(l=null==c?void 0:c.enabled)&&void 0!==l&&l?60*((null==c?void 0:c.global_min_separation_seconds)||0):0;a[n]=e(e({},s),{global_min_separation_seconds:_})}else a[n]="inventory_rules"===n?e(e({},s),{respect_inventory_code:null==c?void 0:c.respect_inventory_code}):"break_code_rules"===n?e(e({},s),{respect_break_code:null==c?void 0:c.respect_break_code}):"is_default_enabled"===n?null!=c&&c:s})}),a},Rr=function(e,n,t){void 0===t&&(t="variantType");var i=null==e?void 0:e[n];if(!i)return{label:Mr(e),isDefault:!1};var r=i[t]||"",a=U(r);return{label:"variant ".concat(n+1),isDefault:a}},Dr=function(e,n){var t=U(e);return{label:"variant ".concat(n+1),isDefault:t}},jr=function(e,n,t){var i;void 0===t&&(t="");var r=null===(i=Wn.get(e))||void 0===i?void 0:i.get(n);return r?r.is_default_enabled?"Default":"Variant":U(t)?"Default":"Variant"},Vr=function(n,o){return void 0===o&&(o=!1),t(void 0,void 0,void 0,function(){var t,l,s,u,d,c,_,p,g,w,h,b,A,T,k,S,C;return i(this,function(i){switch(i.label){case 0:t=Er(fe.tiers),l=M.getState().backwardCompatibility,s=en.current,u=Lr(it,Bt,Wn,s),i.label=1;case 1:return i.trys.push([1,3,,4]),ye(F),Se(""),d=Or(u),c=m(),_=[],p=[],g=(ft||[])[s]||{},console.log("originalItem check :",g,s),fe.tiers.forEach(function(i){var r,a,o,u,v,f,w,h,b,A,T,M,I,k,S,C=i.toLowerCase().replace(/ /g,"_");p.push(C);var N=(null===(r=ot.get(C))||void 0===r?void 0:r.get(s))||"",x=(null===(a=ut.get(C))||void 0===a?void 0:a.get(s))||[],E=(null===(o=_t.get(C))||void 0===o?void 0:o.get(s))||[];if(!1===l){var O=[e(e({},d&&{config:e({master_name:Un.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},tierLinkId:c,variant:Cr(N),conditions_whentoapply:x.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:E.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),isDefault:null===(f=null===(v=null===(u=Wn.get(C))||void 0===u?void 0:u.get(s))||void 0===v?void 0:v.is_default_enabled)||void 0===f||f,tier_id:(null===(w=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===C||e.tier_name.toLowerCase()===C.replace(/_/g,"")}))||void 0===w?void 0:w.tier_id)||"",topic_id:null,scope_id:(null==ee?void 0:ee.ruleSetId)||"",question_title:et,variantType:jr(C,s,g.variant_type||g.variantType),instantLearningType:Un.INSTANT_LEARNING_TYPE,is_user_accepted_risk:!1,propagation:!1,applicationMappingId:ve,modeId:"019e1e39-2030-7775-8312-0ad525700588"})];_.push(y(O,Un.ASSISTANT_NAME))}else{O={status:"approved",metadata:e(e({userName:null!==(h=null==or?void 0:or.firstname)&&void 0!==h?h:"",userEmailId:null!==(b=null==or?void 0:or.email)&&void 0!==b?b:"",llm:D.MODEL,isVariantFlow:!0},d&&{config:e({master_name:D.CONFIG_MASTER_NAME},d)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:c,variant:Cr(N),conditions_whentoapply:x.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),conditions_whennottoapply:E.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" OR "),referenceVariantID:null,referenceVariantIDVersion:null,scope:t[0]||{name:D.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:D.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null===(M=null===(T=null===(A=Wn.get(C))||void 0===A?void 0:A.get(s))||void 0===T?void 0:T.is_default_enabled)||void 0===M||M,tier:{name:i.split(" ").join("").toLowerCase(),tierGroupName:D.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(i.split(" ")[1]||"1"),tier_id:(null===(I=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===C||e.tier_name.toLowerCase()===C.replace(/_/g,"")}))||void 0===I?void 0:I.tier_id)||""},topic:{id:null,value:"".concat(fe.station||X,"RuleSet"),description:null},categories:[{id:null,value:D.CATEGORY,description:D.CATEGORY}],originalQuestion:et,questionId:n.get(C)||null,variantType:jr(C,s,g.variant_type||g.variantType),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(k=null==or?void 0:or.email)&&void 0!==k?k:"",instantLearningType:D.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(S=null==g?void 0:g.is_user_accepted_risk)&&void 0!==S?S:null==jt?void 0:jt.is_user_accepted_risk)},isAgentsFeedback:!0})};_.push(y(O,Un.ASSISTANT_NAME))}}),[4,Promise.all(_)];case 2:return w=i.sent(),Re(!1),console.log("✅ All feedback published:",w),ye(P),Ae(!0),h=new Map,w.forEach(function(e,n){var t,i,r=p[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=h.get(r)||[];o.push({id:a,action:"new"}),h.set(r,o)}}),M.getState().setCreatedVariantInfo(Array.from(h.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(k=hi.current)||void 0===k||k.show({severity:"success",sticky:!1,life:6e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Learning saved successfully!"}))]}))}),Ee.current=setTimeout(function(){Ri||o?(console.log("Closing modal after save success",{isCloseModal:Ri,forceClose:o}),ra()):Tr(!0)},3e3),[3,4];case 3:return b=i.sent(),console.error("❌ Error publishing feedback:",b),Re(!1),ye(G),xe(!0),A=(null===(S=null==b?void 0:b.response)||void 0===S?void 0:S.data)||{},console.log("errorData: ",A),(T="Variant already exists"===(null==A?void 0:A.message))||409===(null==b?void 0:b.status)?Se('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>'):Se(((null==A?void 0:A.message)||(null==A?void 0:A.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(C=hi.current)||void 0===C||C.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(v,{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==b?void 0:b.status)?"Similar rule already exists. Please update and try again.":(null==A?void 0:A.message)||(null==A?void 0:A.detail)||"Something went wrong while saving the learning!"}))]}))}),[3,4];case 4:return[2]}})})},Pr=function(){return t(void 0,void 0,void 0,function(){var t,o,l,s,u,d,c,_,p,g,w,b,A,T,k,S,C,N,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:t=M.getState().tiers,o=Lr(it,Bt,Wn),l=Or(o),s=en.current,u=(ft||[])[s]||{},d=(null==jt?void 0:jt.variant_type)||u.variant_type||"",i.label=1;case 1:for(i.trys.push([1,3,,4]),ye(F),Se(""),_=(c=ie||[]).length>0?null===(O=c.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===O?void 0:O.link_id:null,p=(null===(L=fe.tiers[0])||void 0===L?void 0:L.toLowerCase().replace(/ /g,"_"))||"tier_1",g=(null===(R=ot.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 A=[],T=[],k=Er(fe.tiers),fe.tiers.forEach(function(n){var i=n.toLowerCase().replace(/ /g,"_"),r=t.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=ot.get(i),o=ut.get(i),s=_t.get(i);w.forEach(function(t,c){var v,p,f,g,w,b,M,I,S,C,N,x,E,O,L,R,D,j,V,P,G,F,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){T.push({tierKey:i,payloadType:"new"});var $=Lr(it,Bt,Wn,c),X=Or($);console.log("variant in save edit add part :",t,u);var te={status:"approved",metadata:e(e({userName:null!==(v=null==or?void 0:or.firstname)&&void 0!==v?v:"",userEmailId:null!==(p=null==or?void 0:or.email)&&void 0!==p?p:"",llm:Un.MODEL,isVariantFlow:!0},X&&{config:e({master_name:Un.CONFIG_MASTER_NAME},X)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:_||m(),variant:Cr(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:Un.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Un.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(w=null===(g=null===(f=Wn.get(i))||void 0===f?void 0:f.get(c))||void 0===g?void 0:g.is_default_enabled)&&void 0!==w?w:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{name:n.split(" ").join("").toLowerCase(),tierGroupName:Un.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(n.split(" ")[1]||"1")},topic:{id:null,value:"".concat(fe.station,"RuleSet"),description:null},categories:[{id:null,value:Un.CATEGORY,description:Un.CATEGORY}],originalQuestion:et,questionId:null==ne?void 0:ne.ruleId,variantType:jr(i,c,u.variant_type||""),parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(b=null==or?void 0:or.email)&&void 0!==b?b:"",instantLearningType:Un.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(I=null===(M=(ft||[])[c])||void 0===M?void 0:M.is_user_accepted_risk)&&void 0!==I?I:null==jt?void 0:jt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("payload (publish new variant)",te),A.push(y(te,Un.ASSISTANT_NAME))}else{T.push({tierKey:i,payloadType:"existing",existingId:t.variantId});var ie=t.variantId===$i,re=jr(i,c,ie?d||t.variantType||"":t.variantType||"");console.log("isThisVariantBeingEdited variantTypeToUse :",re,ie,t,$i);var ae={variantId:t.variantId,ruleDesc:(null==ee?void 0:ee.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=Wn.get(i))||void 0===S?void 0:S.get(c))||void 0===C?void 0:C.is_default_enabled)&&void 0!==N?N:U(t.variantType||t.variant_type||(0===c?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||n,tier_priority:null!==(x=null==r?void 0:r.tier_priority)&&void 0!==x?x:null},scope_id:(null==ee?void 0:ee.ruleSetId)||"",description:Cr(z)||"",topic:"".concat(fe.station,"RuleSet"),configuration:(null==l?void 0:l.config_data)||{},tierLinkId:null!=_?_:null,variantType:re,is_user_accepted_risk:!!(null!==(O=null===(E=(ft||[])[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=(wt.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===t.variantId}),le=!0;if(oe){var se=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},ue=se(et)===se(oe.title),de=se(z)===se(oe.rule_description),ce=se(ae.whenToApply)===se(oe.wta),_e=se(ae.whenNotToApply)===se(oe.wnta),ve=!!ae.isDefault===U(oe.variant_type),pe=oe.scheduling_config||{},ge=null!==(D=null!==(L=pe.order_global_min_separation_seconds)&&void 0!==L?L:null===(R=pe.order_rules)||void 0===R?void 0:R.global_min_separation_seconds)&&void 0!==D?D:0,me=null!==(P=null!==(j=pe.advertiser_global_min_separation_seconds)&&void 0!==j?j:null===(V=pe.advertiser_rules)||void 0===V?void 0:V.global_min_separation_seconds)&&void 0!==P?P:0,we=null!==(J=null!==(F=null===(G=pe.inventory_rules)||void 0===G?void 0:G.respect_inventory_code)&&void 0!==F?F:pe.respect_inventory_code)&&void 0!==J&&J,ye=null!==(W=null!==(B=null===(H=pe.break_code_rules)||void 0===H?void 0:H.respect_break_code)&&void 0!==B?B:pe.respect_break_code)&&void 0!==W&&W,he=(null===(K=Wn.get(i))||void 0===K?void 0:K.get(c))||Hn,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&&ve&&be&&(le=!1)}le?(console.log("payloadv (update existing variant)",ae),A.push(h(ae,null!==(Y=null==or?void 0:or.email)&&void 0!==Y?Y:""))):(console.log("[saveEditedVariant] No changes for variant ".concat(t.variantId,", skipping API call")),A.push(Promise.resolve({data:{id:t.variantId},skipped:!0})))}})}),[4,Promise.all(A)];case 2:return S=i.sent(),console.log("✅ All variants updated:",S),ye(P),Ae(!0),Re(!1),C=new Map,S.forEach(function(e,n){var t,i;if(!(null==e?void 0:e.skipped)){var r=T[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id);a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data);var o="existing"===r.payloadType?r.existingId:a;if(o&&"string"==typeof o){var l=C.get(r.tierKey)||[];l.push({id:o,action:r.payloadType}),C.set(r.tierKey,l)}}}),M.getState().setCreatedVariantInfo(Array.from(C.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),null===(D=hi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ee.current=setTimeout(function(){ra()},3e3),[3,4];case 3:return N=i.sent(),console.error("❌ Error updating variant:",N),ye(G),xe(!0),Re(!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)?Se('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>'):Se(((null==x?void 0:x.message)||(null==x?void 0:x.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=hi.current)||void 0===V||V.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(v,{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]}})})},Gr=function(){return t(void 0,void 0,void 0,function(){var n,t,o,l,s,u,d,c,_,p,g,w,b,A,T,k,S,C,N,x,E,O,L,R,D,j,V;return i(this,function(i){switch(i.label){case 0:n=M.getState().tiers,t=Lr(it,Bt,Wn),o=Or(t),i.label=1;case 1:return i.trys.push([1,9,,10]),ye(F),Se(""),0===(l=Array.isArray(ft)?ft:[]).length?(console.warn("No variants found to save."),ye(G),[2]):(s=l.filter(function(e){return e.is_new_variant}),u=l.filter(function(e){return!e.is_new_variant&&(null==e?void 0:e.variant_id)}),console.log("[saveLoadAndEditVariant] New: ".concat(s.length,", Existing: ").concat(u.length)),d=u.length>0?null===(R=u.find(function(e){return(null==e?void 0:e.link_id)&&""!==e.link_id.trim()}))||void 0===R?void 0:R.link_id:null,c=[],_=[],p=[],g=[],w=Er(fe.tiers),fe.tiers.forEach(function(t){var i=t.toLowerCase().replace(/ /g,"_"),r=n.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===i||e.tier_name.toLowerCase()===i.replace(/_/g,"")}),a=ot.get(i),s=ut.get(i),u=_t.get(i);l.forEach(function(n,l){var v,f,y,b,A,T,M,I,k,S,C,N,x,E,O,L,R,D,j,V,P,G,F,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=Lr(it,Bt,Wn,l),Z=Or(Q),$=jr(i,l,n.variant_type||n.variantType||""),ne={status:"approved",metadata:e(e({userName:null!==(v=null==or?void 0:or.firstname)&&void 0!==v?v:"",userEmailId:null!==(f=null==or?void 0:or.email)&&void 0!==f?f:"",llm:Un.MODEL,isVariantFlow:!0},Z&&{config:e({master_name:Un.CONFIG_MASTER_NAME},Z)}),{datasource:{type:"link",ref:"www.something.com",tag:"something"},variant:{tierLinkId:d||m(),variant:Cr(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:Un.SCOPE_NAME,parentScopeId:null,scopeRowId:(null==ee?void 0:ee.ruleSetId)||"",value:{scopeName:(null==ee?void 0:ee.ruleSetName)||"",scopeId:"Audacy_"+m(),customScopeGroupName:Un.CUSTOM_SCOPE_GROUP_NAME,description:(null==ee?void 0:ee.ruleSetDesc)||""}},overriden:!1,isDefault:null!==(A=null===(b=null===(y=Wn.get(i))||void 0===y?void 0:y.get(l))||void 0===b?void 0:b.is_default_enabled)&&void 0!==A?A:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{name:t.split(" ").join("").toLowerCase(),tierGroupName:Un.CUSTOM_SCOPE_GROUP_NAME,tierPriority:parseInt(t.split(" ")[1]||"1"),tier_id:(null==r?void 0:r.tier_id)||""},topic:{id:null,value:"".concat(fe.station||X,"RuleSet"),description:null},categories:[{id:null,value:Un.CATEGORY,description:Un.CATEGORY}],originalQuestion:et,questionId:Rn.current||null,variantType:$,parameterizedQuestion:null,created_at:(new Date).toISOString(),created_by:null!==(T=null==or?void 0:or.email)&&void 0!==T?T:"",instantLearningType:Un.INSTANT_LEARNING_TYPE,appliedTagsIL:[],tagMappingInfoIL:{},is_user_accepted_risk:!!(null!==(M=null==n?void 0:n.is_user_accepted_risk)&&void 0!==M?M:null==jt?void 0:jt.is_user_accepted_risk)},isAgentsFeedback:!0})};console.log("[saveLoadAndEditVariant] publish payload (new variant)",ne),_.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===rr?(null==jt?void 0:jt.variant_type)||n.variant_type||n.variantType||"":n.variant_type||n.variantType||"",ie=($=jr(i,l,te),{variantId:n.variant_id,ruleDesc:(null==ee?void 0:ee.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=Wn.get(i))||void 0===I?void 0:I.get(l))||void 0===k?void 0:k.is_default_enabled)&&void 0!==S?S:U(n.variantType||n.variant_type||(0===l?"Default":"variant")),tier:{tier_id:(null==r?void 0:r.tier_id)||"",tier_name:(null==r?void 0:r.tier_name)||t,tier_priority:null!==(C=null==r?void 0:r.tier_priority)&&void 0!==C?C:null},scope_id:(null==ee?void 0:ee.ruleSetId)||"",description:Cr(K)||"",topic:"".concat(fe.station,"RuleSet"),configuration:(null==o?void 0:o.config_data)||{},tierLinkId:null!=d?d:null,variantType:$,is_user_accepted_risk:!!(null!==(N=null==n?void 0:n.is_user_accepted_risk)&&void 0!==N?N:null===(x=(ft||[])[l])||void 0===x?void 0:x.is_user_accepted_risk),is_enabled:n.is_enabled}),re=(wt.get(i)||[]).find(function(e){return(null==e?void 0:e.variant_id)&&e.variant_id===(null==n?void 0:n.variant_id)}),ae=!0;if(re){var oe=function(e){var n=(e||"").trim();return(n=q(n)).replace(/\s+/g," ").replace(/(\s*OR\s*)/g," OR ")},le=oe(et)===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===U(re.variant_type),_e=re.scheduling_config||{},ve=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,pe=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!==(G=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!==G&&G,me=null!==(H=null!==(J=null===(F=_e.break_code_rules)||void 0===F?void 0:F.respect_break_code)&&void 0!==J?J:_e.respect_break_code)&&void 0!==H&&H,we=(null===(B=Wn.get(i))||void 0===B?void 0:B.get(l))||Hn,ye=we.order_rules.enabled===ve>0&&we.order_rules.global_min_separation_seconds===Math.floor(ve/60)&&we.advertiser_rules.enabled===pe>0&&we.advertiser_rules.global_min_separation_seconds===Math.floor(pe/60)&&we.inventory_rules.respect_inventory_code===ge&&we.break_code_rules.respect_break_code===me;le&&se&&ue&&de&&ce&&ye&&(ae=!1)}ae?(console.log("[saveLoadAndEditVariant] update payload (existing variant)",ie),c.push(h(ie,null!==(W=null==or?void 0:or.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),A=[],T=0,k=_,i.label=3;case 3:if(!(T<k.length))return[3,8];S=k[T],i.label=4;case 4:return i.trys.push([4,6,,7]),[4,y(S.payload,Un.ASSISTANT_NAME)];case 5:return C=i.sent(),A.push(C),[3,7];case 6:throw N=i.sent(),console.error("❌ Error publishing new variant:",N),N;case 7:return T++,[3,3];case 8:return console.log("✅ All new variants published:",A),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)}}}),A.forEach(function(e,n){var t,i,r=g[n],a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.id)||(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.variant_id)&&e.data.variant_id||(null==e?void 0:e.id)||(null==e?void 0:e.variant_id)&&e.variant_id;if(a||"string"!=typeof(null==e?void 0:e.data)||(a=e.data),a&&"string"==typeof a){var o=x.get(r.tierKey)||[];o.push({id:a,action:"new"}),x.set(r.tierKey,o)}}),M.getState().setCreatedVariantInfo(Array.from(x.entries()).map(function(e){return{tierName:e[0],variants:e[1]}})),ye(P),Ae(!0),Re(!1),We.current=!1,null===(D=hi.current)||void 0===D||D.show({severity:"success",sticky:!1,life:3e3,className:I.toastSuccess,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(f,{className:I.iconSuccess}),a("span",e({className:"".concat(I.toastTitle," ").concat(I.toastTitleSuccess)},{children:"Success"}))]})),a("p",e({className:"".concat(I.toastMessage," ").concat(I.toastMessageSuccess)},{children:"Changes saved successfully!"}))]}))}),Ee.current=setTimeout(function(){ra()},3e3),[3,10];case 9:return E=i.sent(),console.error("❌ Error updating variant:",E),ye(G),xe(!0),Re(!1),O=(null===(j=null==E?void 0:E.response)||void 0===j?void 0:j.data)||{},console.log("errorData: ",O),(L="Variant already exists"===(null==O?void 0:O.message))||409===(null==E?void 0:E.status)?Se('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>'):Se(((null==O?void 0:O.message)||(null==O?void 0:O.detail)||"Error Occurred while saving the rule.")+'Please try again.<br/><button class="clickable-button" data-value="Save this Learning">Retry</button>'),null===(V=hi.current)||void 0===V||V.show({severity:"error",sticky:!1,className:I.toastError,content:r("div",e({className:I.toastContent},{children:[r("div",e({className:I.toastHeaderLeft},{children:[a(v,{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]}})})},Fr=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(){Vi&&!fi&&(console.log("isSaveRule received from agent — calling publish APIs directly."),Pi(!1),ne||ie?Pr():!0===We.current?Gr():t(void 0,void 0,void 0,function(){var e,n,t,r,a,o,l,s;return i(this,function(u){switch(u.label){case 0:u.trys.push([0,5,,6]),ye(F),e=new Map,n=function(n){var t,r,a,o,l,u;return i(this,function(i){switch(i.label){case 0:if(t=n.toLowerCase().replace(/ /g,"_"),r=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return e.set(t,null),[2,"continue"];o={question:et,orgName:Un.ORGANIZATION_NAME,scope_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),e.set(t,(null===(s=null==l?void 0:l.data)||void 0===s?void 0:s.id)||null),console.log("✅ Question saved for ".concat(n,":"),l),[3,4];case 3:return u=i.sent(),console.error("❌ Error saving question for ".concat(n,":"),u),e.set(t,null),[3,4];case 4:return[2]}})},t=0,r=fe.tiers,u.label=1;case 1:return t<r.length?(a=r[t],[5,n(a)]):[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return Vr(e),[3,6];case 5:return o=u.sent(),l=new Map,fe.tiers.forEach(function(e){l.set(e.toLowerCase().replace(/ /g,"_"),null)}),Vr(l),console.error("❌ Error saving Instant Learning Question:",o),[3,6];case 6:return[2]}})}))},[Vi,fi]);var qr=(null===(B=(null===(H=null==fe?void 0:fe.tiers)||void 0===H?void 0:H[0])||te||"Tier 1")||void 0===B?void 0:B.toLowerCase().replace(/ /g,"_"))||"tier_1",Ur=null!==(W=null!=xt?xt:re)&&void 0!==W?W:0,Jr=null!=xt,Hr=Jr?null==ft?void 0:ft[Ur]:null,Br=ft&&(null==ft?void 0:ft.find(function(e){return e&&!e.is_readOnly&&((null==e?void 0:e.new_variant_id)&&Ut.includes(e.new_variant_id)||(null==e?void 0:e.variant_id)&&Gt.includes(e.variant_id))})),Wr=(null==Hr?void 0:Hr.new_variant_id)&&Ut.includes(Hr.new_variant_id)?Hr.new_variant_id:(null==Br?void 0:Br.new_variant_id)&&Ut.includes(Br.new_variant_id)?Br.new_variant_id:"",Kr=!(!ne&&!ie),Yr=function(n){var t={},i=fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),r=(null==fe?void 0:fe.station)+"RuleSet",a=i.map(function(e){var n=je.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return n.forEach(function(n,o){var l,s,u,d,c,_,v=(null==n?void 0:n.variant_id)&&n.variant_id||Gt[o]||"new_variant_".concat(o),p=(null===(l=n.scope)||void 0===l?void 0:l[0])||qr,f=ot.get(p),g=ut.get(p),m=_t.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))||[],A=b.length>0?b.map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n "):n.wnta||"",T=Wn.get(p),M=null==T?void 0:T.get(o),I={};M&&Object.keys(M).length>0?I=e(e({},M),{order_rules:e(e({},M.order_rules),{global_min_separation_seconds:60*((null===(s=M.order_rules)||void 0===s?void 0:s.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},M.advertiser_rules),{global_min_separation_seconds:60*((null===(u=M.advertiser_rules)||void 0===u?void 0:u.global_min_separation_seconds)||0)})}):n.scheduling_config&&(I=n.scheduling_config),t[v]={rule_title:et,variant_description:w,wta:h,ruleset_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a,wnta:A,scope:i,scope_rule_set:r,scheduling_config:I,is_user_accepted_risk:!(null===(_=null!==(d=null==n?void 0:n.is_user_accepted_risk)&&void 0!==d?d:null===(c=(ft||[])[o])||void 0===c?void 0:c.is_user_accepted_risk)||void 0===_||!_)}}),t};bn&&console.log("customMetaData.ui_state for addvariant flow",Yr(bt));var zr=M(function(e){return e.selectedRuleSetId}),Qr={send_metadata_to_orchestrator:!1,default:["scope"],app_mapping_id:ve,ui_state:Kr?{variants:function(){var n={},t=Wn.get(qr);if(!t)return n;var i=ot.get(qr),r=ut.get(qr),a=_t.get(qr),o=fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),l=(null==fe?void 0:fe.station)+"RuleSet",s=o.map(function(e){var n=je.find(function(n){return n.tier_name.toLowerCase().replace(/ /g,"_")===e||n.tier_name.toLowerCase()===e.replace(/_/g,"")});return(null==n?void 0:n.tier_id)||""}).filter(Boolean);return t.forEach(function(u,d){var c,_,v,p,f,g,m=null===(c=null==ie?void 0:ie[d])||void 0===c?void 0:c.variantId,w=(ft||[])[d],y=(null==w?void 0:w.new_variant_id)||"",h=m||y||Gt[d]||"variant_".concat(d),b=(null==i?void 0:i.get(d))||"",A=((null==r?void 0:r.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",T=((null==a?void 0:a.get(d))||[]).map(function(e){return e.text}).filter(function(e){return""!==e.trim()}).join(" \\n ")||"",M=t.get(d),I={};M&&Object.keys(M).length>0&&(I=e(e({},M),{order_rules:e(e({},M.order_rules),{global_min_separation_seconds:60*((null===(_=M.order_rules)||void 0===_?void 0:_.global_min_separation_seconds)||0)}),advertiser_rules:e(e({},M.advertiser_rules),{global_min_separation_seconds:60*((null===(v=M.advertiser_rules)||void 0===v?void 0:v.global_min_separation_seconds)||0)})})),n[h]={rule_title:et,variant_description:b,wta:A,ruleset_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:s,wnta:T,scope:o,scope_rule_set:l,scheduling_config:I,is_user_accepted_risk:!(null===(g=null!==(p=null==w?void 0:w.is_user_accepted_risk)&&void 0!==p?p:null===(f=null==ie?void 0:ie[d])||void 0===f?void 0:f.is_user_accepted_risk)||void 0===g||!g)}}),n}()}:function(){var n,t,i,r,a,o,l=(ft||[]).findIndex(function(e){return!0===e.is_new_variant}),s=-1;return-1!==l?s=l:fn?s=-1:bn||(s=Ur),{new_current_variant:-1!==s?{rule_title:et,rule_description:(null===(n=ot.get(qr))||void 0===n?void 0:n.get(s))||"",wta:(null===(i=null===(t=ut.get(qr))||void 0===t?void 0:t.get(s))||void 0===i?void 0:i.map(function(e){return Fr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",wnta:(null===(a=null===(r=_t.get(qr))||void 0===r?void 0:r.get(s))||void 0===a?void 0:a.map(function(e){return Fr(e.text)}).filter(function(e){return""!==e}).join(" \\n "))||"",scope:fe.tiers.map(function(e){return null==e?void 0:e.toLowerCase().replace(/ /g,"_")}),scope_rule_set:(null==fe?void 0:fe.station)+"RuleSet",scheduling_config:function(){var n,t,i,r=null===(n=Wn.get(qr))||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=(ft||[])[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:bn?Yr(bt):{}}}(),rule_id_in_current_session:St,new_variant_id:function(){var e;return Jr&&ne?(null===(e=null==ie?void 0:ie[Ur])||void 0===e?void 0:e.variantId)?null:Wr:null}(),edit_variant_id:On,rule_id:Rn.current,backward_compatibility:M.getState().backwardCompatibility,ruleset_id:zr,current_variants_length:ne?Array.isArray(ft)&&ft.length>0?Math.max((null===(K=null==ne?void 0:ne.variants)||void 0===K?void 0:K.length)||0,ft.length):null===(Y=null==ne?void 0:ne.variants)||void 0===Y?void 0:Y.length:void 0,tiers:M.getState().tiers,authToken:(null==or?void 0:or.accessToken)||""},Zr=Mr(bt),$r={ruleTitle:et,scopeData:fe,variantsByTier:Array.from(Wn.keys()).reduce(function(n,t){var i=Wn.get(t)||new Map,r=ot.get(t)||new Map,a=ut.get(t)||new Map,o=_t.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=(ft||[])[n]||{};console.log("Original item for tier",t,"index",n,":",d);var c={label:"",isDefault:!1};if(d.is_variant&&!U(d.variant_type))c={label:"",isDefault:!1};else if(ie&&ie.length>0){c=Rr(ie,n,"variantType"),console.log("Found matching variant at index",n,":",c);var _=ie[n];if(_){if(!c.label){var v=_.variantType||"",p=U(v);c={label:"variant ".concat(n+1),isDefault:p}}if(_.variantId===$i)(g=d.variant_type||(null==jt?void 0:jt.variant_type))&&(c=Dr(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:Mr(ie),isDefault:!1},console.log("No match found, using getNextVariantType:",c)}else if(bt&&bt.length>0){if(c=Rr(bt,n,"variant_type"),console.log("Found matching variant at index",n,":",c),We.current){var f=bt[n];if((null==f?void 0:f.variant_id)===rr||(null==f?void 0:f.variantId)===rr)(g=d.variant_type||(null==jt?void 0:jt.variant_type))&&(c=Dr(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:Zr,isDefault:U(g)}}console.log("Computed variant data for tier",t,"index",n,":",c);var m=null!==(u=null===(s=i.get(n))||void 0===s?void 0:s.is_default_enabled)&&void 0!==u?u:c.isDefault;console.log("live is default :",m);var w="variant ".concat(l+1),y=r.get(n)||"";return{variantId:Gt[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)||Hn,isReadOnly:d.is_readOnly||!1,is_variant:d.is_variant||!1,reasoning:{ruleDescription:Sr(y),whenToApply:Sr(d.wta),whenNotToApply:Sr(d.wnta),configData:Sr(d.action)}}}),n},{}),citation:ii,fieldCitations:_i,citations:oi};console.log("templateState",$r);var Xr={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;nt(i),Ni(function(n){if(n.ruleTitle){var t=e({},n);return delete t.ruleTitle,t}return n})},setRuleDescription:function(e,n,t){return _r(e,n,t)},addWhenToApply:function(e,n){return vr(e,n)},removeWhenToApply:function(e,n,t){return pr(e,n,t)},editWhenToApply:function(e,n,t,i){return fr(e,n,t,i)},addWhenNotToApply:function(e,n){return gr(e,n)},removeWhenNotToApply:function(e,n,t){return mr(e,n,t)},editWhenNotToApply:function(e,n,t,i){return wr(e,n,t,i)},addNewVariant:function(e){return yr(e)},onScopeChange:br,onConfigChange:function(e,n,t,i){return Ar(e,n,t,i)}},ea={},na={};Wn.forEach(function(n,t){ea[t]=new Map,na[t]=new Map,n.forEach(function(n,i){ea[t].set(i,[e({key:"order_rules",label:"Order"},n.order_rules),e({key:"advertiser_rules",label:"Advertiser"},n.advertiser_rules)]),na[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 ta=_(function(){if(te){if(1===fe.tiers.length)return 0;var e=fe.tiers.findIndex(function(e){return e.toLowerCase()===te.toLowerCase()});return e>=0?e:0}},[te,fe.tiers]),ia=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:ea,togglesByTier:na,highlights:Yt,highlightedIds:Zt,openSections:zn,setOpenSections:Qn,setSendMessageInChat:Rt,isAiStreaming:fi,defaultTierOpen:ta,defaultVariantOpen:fn?void 0:xt,autoScrollVariantIndex:fn?void 0:xt,activeVariantAccordionIndex:fn?void 0:xt,setActiveVariantAccordionIndex:function(e){Et(e),null!=e&&setTimeout(function(){gn(!1)},100)},validationErrors:Ci,activeEditId:kn,setActiveEditId:Sn,pendingEditId:Nn,setPendingEditId:xn,conflictReason:Ei,usedFor:ne||ie?"Edit":"Create"},Jn),{scrollTrigger:ei});console.log(xt,"editVariantIndex checking"),d(function(){},[Q]),d(function(){if(!fi&&Mt&&!!(!ne&&!ie)){var e=n([],ft,!0).reverse().findIndex(function(e){return"variant"===e.action||e.is_variant});-1===e||ft.length,-1!==e&&(console.log("Post-stream: Focusing new variant at index",e),Et(e))}},[fi,Mt]);var ra=function(){Ee.current&&(clearTimeout(Ee.current),Ee.current=null),We.current=!1,Z(),Tr()},aa=function(){var e={};et.trim()||(e.ruleTitle="Rule Title is required"),fe.station||(e.station="Station Rule Set is required"),fe.tiers&&0!==fe.tiers.length||(e.tiers="At least one tier must be selected");return fe.tiers.map(function(e){return e.toLowerCase().replace(/ /g,"_")}).forEach(function(n){var t=ot.get(n),i=ut.get(n),r=Wn.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 oa(r,a,o){var l,s,u,d,c,_;return void 0===o&&(o=!1),t(this,void 0,void 0,function(){var t,v,p,f,g,m,w,y,h,A,T,M,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,v=(null==r?void 0:r.variant_id)||null,Tn.current&&jn.current===t)return console.log("[handleAILoadAction] Already fetching question ID, skipping duplicate request:",t),[2];if(Rn.current===t&&!o)return console.log("[handleAILoadAction] Question ID unchanged, updating variant focus only:",v),Ln(v),v?(-1!==(p=(ft||[]).findIndex(function(e){return e.is_new_variant}))&&(ki(!0),Hi("Removing new variant..."),Ki("Please wait while we remove new variant.")),gt(function(e){if(!Array.isArray(e))return e;var n=e.filter(function(e){return!e.is_new_variant}),t=n.findIndex(function(e){return e.variant_id===v});return-1!==t&&setTimeout(function(){Et(t),ni(function(e){return e+1}),yi.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})})(Kn),f(lt),f(dt),f(vt),Ft(function(e){var t=n([],e,!0);return t.length>p&&t.splice(p,1),t})),!1===Tn.current&&(Tn.current=!0,-1!==p&&(null===(l=hi.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}))),gn(!1)):(console.log("lastLoadedQuestionIdRef.current in else",Rn.current),null===Rn.current&&(ki(!0),Hi("Adding new variant..."),Ki("Please wait while we add new variant."))),[2];console.log("User Action: fetching fresh variant info for question",t),Mn.current.clear(),Mn.current.add(t),ki(!0),Hi("Loading variants..."),console.log("reaching here in load and edit"),Ki("Please wait while we fetch the latest variant data."),Tn.current=!0,jn.current=t,i.label=1;case 1:return i.trys.push([1,5,6,10]),g=Date.now(),[4,b(t,(null==ee?void 0:ee.ruleSetId)||"")];case 2:return m=i.sent(),(w=Date.now()-g)<3e3?[4,new Promise(function(e){return setTimeout(e,3e3-w)})]:[3,4];case 3:i.sent(),i.label=4;case 4:return 0===(y=(null===(s=null==m?void 0:m.data)||void 0===s?void 0:s.variants)||[]).length?(console.warn("No variants found for question_id",t),ki(!1),Hi(""),null===(u=hi.current)||void 0===u||u.show({severity:"error",summary:"Error",detail:"No variants found for this question.",life:3e3}),[2]):(We.current=!0,Tn.current=!0,h=(null===(d=null==m?void 0:m.data)||void 0===d?void 0:d.ruleTitle)||"",nt(h),A=null===(c=null==m?void 0:m.data)||void 0===c?void 0:c.tier,T="tier_1",M="Tier 1",I="1",A&&((k=String(A).match(/(\d+)/))?(S=k[1],I=S,T="tier_".concat(S),M="Tier ".concat(S)):(T=String(A).toLowerCase().trim().replace(/ /g,"_"),M=T.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),I=T.includes("2")?"2":"1")),console.log("[handleAILoadAction] Detected Tier: ".concat(M," (ID: ").concat(I,", Key: ").concat(T,")")),ge({station:X||"global",tiers:[M]}),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,_=e.scheduling_config||{};l.set(n,{order_rules:{enabled:!!_.order_global_min_separation_seconds||!!(null===(t=_.order_rules)||void 0===t?void 0:t.global_min_separation_seconds),global_min_separation_seconds:Math.floor((_.order_global_min_separation_seconds||(null===(i=_.order_rules)||void 0===i?void 0:i.global_min_separation_seconds)||0)/60)},advertiser_rules:{enabled:!!_.advertiser_global_min_separation_seconds||!!(null===(r=_.advertiser_rules)||void 0===r?void 0:r.global_min_separation_seconds),global_min_separation_seconds:Math.floor((_.advertiser_global_min_separation_seconds||(null===(a=_.advertiser_rules)||void 0===a?void 0:a.global_min_separation_seconds)||0)/60)},inventory_rules:{respect_inventory_code:!!_.respect_inventory_code||!!(null===(o=_.inventory_rules)||void 0===o?void 0:o.respect_inventory_code)},break_code_rules:{respect_break_code:!!_.respect_break_code||!!(null===(c=_.break_code_rules)||void 0===c?void 0:c.respect_break_code)},is_default_enabled:U(e.variantType||e.variant_type)}),s.set(n,q(e.rule_description||""));var v=e.wta?e.wta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];u.set(n,v);var p=e.wnta?e.wnta.split(" OR ").map(function(e){return e.trim()}).filter(function(e){return""!==e}).map(function(e,t){return{id:"edit-wnta-".concat(n,"-").concat(t),text:e,reasoning:""}}):[];d.set(n,p)}),{transformedVariants:o,tierConfigMap:l,tierDescMap:s,tierWtaMap:u,tierWntaMap:d}}(y,h,T,I,t,v),N=C.transformedVariants,x=C.tierConfigMap,E=C.tierDescMap,O=C.tierWtaMap,L=C.tierWntaMap,yt(function(e){var n=new Map(e);return n.set(T,JSON.parse(JSON.stringify(N))),n}),gt(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)}),At(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)}),An(!0),Rn.current=t,Ln(v),R=0,v&&-1!==(D=N.findIndex(function(e){return e.variant_id===v}))&&(R=D),Et(R),ni(function(e){return e+1}),yi.current=R,gn(!1),Kn(function(e){var n=new Map(e);return n.set(T,x),n}),lt(function(e){var n=new Map(e);return n.set(T,E),n}),dt(function(e){var n=new Map(e);return n.set(T,O),n}),vt(function(e){var n=new Map(e);return n.set(T,L),n}),Ni({}),[3,10]);case 5:return j=i.sent(),console.error("Failed to fetch variants by question ID:",j),null===(_=hi.current)||void 0===_||_.show({severity:"error",summary:"Error",detail:"Failed to fetch variants. Please try again.",life:3e3}),[3,10];case 6:return Tn.current=!1,ki(!1),Hi(""),Ki(""),(null==r?void 0:r.is_interpretation_ready)&&(null==r?void 0:r.question_id)&&Rn.current&&On?(console.log("inside edit variant flow",Rn.current,On),gt(function(n){if(!Array.isArray(n))return n;var t=n.map(function(n){return(null==n?void 0:n.variant_id)===On?e(e({},n),a):n}),i=n.findIndex(function(e){return(null==e?void 0:e.variant_id)===On});return console.log(i,"targetIndexif"),-1!==i&&setTimeout(function(){console.log("targetIndex",i),Et(i),ni(function(e){return e+1}),yi.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)&&Rn.current&&!On?(console.log("inside add new variant flow",Rn.current,On),ki(!0),Hi("Adding new variant..."),Ki("Please wait while we add new variant."),[4,new Promise(function(e){return setTimeout(e,3e3)})]):[3,9];case 8:i.sent(),ki(!1),Hi(""),Ki(""),gt(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(){Et(r),ni(function(e){return e+1}),yi.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(){Et(o),ni(function(e){return e+1}),yi.current=o},0),i=n(n([],t,!0),[e(e({},a),{is_new_variant:!0,is_variant:!0})],!1)}}else setTimeout(function(){Et(0),ni(0),yi.current=0},0),i=[e(e({},a),{is_new_variant:!0})];return Gn.current=i,i}),i.label=9;case 9:return[7];case 10:return[2]}})})}var la;return console.log("RuleSet in render",ee),r(o,{children:[a(g,{ref:hi}),a(k,{open:Q,chatAssistantName:Un.ASSISTANT_NAME,organizationName:Un.ORGANIZATION_NAME,baseUrl:Un.BASE_URL,baseWebsocketUrl:Un.BASE_WEBSOCKET_URL,closeFunction:ra,ThinkingBulbIconComponent:a(j,{}),customSections:a(o,{}),customMetaData:Qr,chatTitle:ne?Un.CHAT_TITLE_EDIT.replace("<scope>",(null==ee?void 0:ee.ruleSetName)||""):Un.CHAT_TITLE.replace("<scope>",(null==ee?void 0:ee.ruleSetName)||""),formTitle:Un.FORM_TITLE,showSavedMessage:!1,savedMessage:Me,isError:Ne,errorMessage:ke,isSaving:Le,onSave:function(e){console.log("Save this Learning",e);var n=aa();if(Object.keys(n).length>0)return console.log("validation errors",n),void Ni(n);Re(!0),xe(!1),Se("")},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=aa(),Object.keys(e).length>0?(Ni(e),[2]):(console.log("✅ Bypass Save: Initiated"),ne||ie?[4,Pr()]:[3,2]);case 1:return d.sent(),[3,11];case 2:return!0!==We.current?[3,4]:[4,Gr()];case 3:return d.sent(),[3,11];case 4:d.trys.push([4,10,,11]),ye(F),n=new Map,t=function(e){var t,r,a,o,l,s;return i(this,function(i){switch(i.label){case 0:if(t=e.toLowerCase().replace(/ /g,"_"),r=je.find(function(e){return e.tier_name.toLowerCase().replace(/ /g,"_")===t||e.tier_name.toLowerCase()===t.replace(/_/g,"")}),!(a=null==r?void 0:r.tier_id))return n.set(t,null),[2,"continue"];o={question:et,orgName:Un.ORGANIZATION_NAME,scope_id:(null==ee?void 0:ee.ruleSetId)||"",tier_id:a},i.label=1;case 1:return i.trys.push([1,3,,4]),[4,w(o)];case 2:return l=i.sent(),n.set(t,(null===(u=null==l?void 0:l.data)||void 0===u?void 0:u.id)||null),[3,4];case 3:return s=i.sent(),console.error("❌ Bypass Save: Error saving question for ".concat(e,":"),s),n.set(t,null),[3,4];case 4:return[2]}})},r=0,a=fe.tiers,d.label=5;case 5:return r<a.length?(o=a[r],[5,t(o)]):[3,8];case 6:d.sent(),d.label=7;case 7:return r++,[3,5];case 8:return[4,Vr(n,!0)];case 9:return d.sent(),[3,11];case 10:return l=d.sent(),ye(G),s=new Map,fe.tiers.forEach(function(e){s.set(e.toLowerCase().replace(/ /g,"_"),null)}),Vr(s,!0),console.error("❌ Bypass Save: Error",l),[3,11];case 11:return[2]}})})},headerMessageHandlers:kr,aiResponse:ft,setAIResponse:gt,width:"90vw",height:"90vh",sendMessageInChat:Lt,template:S.CreateRule,isLoading:we===F,templateProps:{state:$r,handlers:Xr,uiState:ia},setSendMessageInChat:Rt,onResetChat:function(){Tr()},onResetRequest:function(){Ti(!0)},isFormDirty:function(){return""!==et.trim()||""!==fe.station||fe.tiers.length>0||Array.from(ot.values()).some(function(e){return Array.from(e.values()).some(function(e){return""!==e.trim()})})||Array.from(ut.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Array.from(_t.values()).some(function(e){return Array.from(e.values()).some(function(e){return e.length>0})})||Wn.size>0||it.size>0},initialChatMessage:ne?(la=ne.ruleTitle||"this rule",null===(z=null==ie?void 0:ie[null!=re?re:0])||void 0===z||z.is_user_accepted_risk,'<p><span>Welcome back! 👋</span>\n <span>I see you want to edit <strong>"'.concat(la,'."</strong></span>\n <span> <strong>What would you like to update? </strong> </span>\n <span>Describe the change you want to make, and I’ll help you edit it.</span>\n </p>')):null!=_e?_e:Un.INITIAL_CHAT_MESSAGE,validateCustom:function(){if(we===P||be)return!1;if(!et||""===et.trim())return!1;if(null!==kn)return!1;if(!fe.station||""===fe.station.trim())return!1;var e=fe.tiers&&fe.tiers.filter(function(e){return e&&""!==e.trim()});if(!e||0===(null==e?void 0:e.length))return!1;for(var n,t=0,i=e.map(function(e){return e.toLowerCase().replace(/ /g,"_")});t<i.length;t++){var r=i[t],a=ot.get(r),o=ut.get(r),l=Wn.get(r);if(!l||0===l.size)return!1;for(var s=0,u=Array.from(l.keys());s<u.length;s++){var d=u[s],c=null==a?void 0:a.get(d);if(!c||""===c.trim())return!1;var _=null==o?void 0:o.get(d);if(!(null==_?void 0:_.some(function(e){return e.text&&""!==e.text.trim()})))return!1}}return!(!Wn||0===Wn.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})})})})(ut)&&!n(_t)&&!Ze)},setCitations:li,isLocked:!0,textareaPlaceholder:"Tell me more about this learning..",saveButtonConfig:{label:ne?"Save Changes":"Save Learning",loadingLabel:r("span",e({style:{display:"flex",gap:"5px",alignItems:"center"}},{children:[a(p,{size:20,color:"white",className:"animate-spin"}),a("span",{children:" Saving Changes..."})]}))},setCurrentRequestId:di,isAiStreaming:fi,setIsAiStreaming:gi,showConfirmReset:Ai,setShowConfirmReset:Ti,confirmReset:function(){Tr(),Ti(!1),ra()},isLoadingVariants:Ii,mainText:Ji,subText:Wi,proposedRule:tn,isFetchingComparison:cr,handleOpenComparison:Ir,showComparison:Fi,setShowComparison:qi,variants:on,onComparisonLinkClick:dr,targetComparisonVariantId:un,highlightedComparisonField:_n,onAddAsVariant:function(){qi(!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==or?void 0:or._id)&&void 0!==a?a:"",user_name:null!==(o=null==or?void 0:or.firstname)&&void 0!==o?o:"",user_email:null!==(l=null==or?void 0:or.email)&&void 0!==l?l:"",assistant_name:Un.ASSISTANT_NAME},n),[4,A(t)];case 1:return i.sent(),[3,3];case 2:throw r=i.sent(),console.error("Failed to submit chat feedback",r),r;case 3:return[2]}})})},handleGlobalClickCapture:function(e){null!==kn&&(e.target.closest('[data-edit-id="'.concat(kn,'"]'))||(e.preventDefault(),e.stopPropagation(),xn(kn)))},isGlobalEditActive:null!==kn,initialDraftMessage:se?ce:"",socketTimeOutInMilliSeconds:Un.SOCKET_TIMEOUT})]})};export{H as default,q as filterAgentText};
|
|
2
2
|
//# sourceMappingURL=InstantLearningModal.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__assign as i}from"tslib";import{jsxs as t,Fragment as e,jsx as n}from"react/jsx-runtime";import{Sparkles as r}from"lucide-react";var o=function(t){var e=t.width,r=void 0===e?"100%":e,o=t.height,d=void 0===o?"10px":o,h=t.style;return n("div",{style:i({width:r,height:d,backgroundColor:"#E2E8F0",borderRadius:"4px",backgroundImage:"linear-gradient(90deg, #E2E8F0 0px, #F1F5F9 40px, #E2E8F0 80px)",backgroundSize:"200px 100%",animation:"shimmer 1.5s ease-in-out infinite"},h)})},d=function(){return t("div",i({style:{display:"flex",flexDirection:"column",gap:"12px",padding:"24px",backgroundColor:"#fff",borderRadius:"12px",border:"1px solid #E2E8F0",width:"100%"}},{children:[n(o,{width:"100%",height:"12px"}),n(o,{width:"85%",height:"10px"}),n("div",{style:{height:"8px"}}),n(o,{width:"60%",height:"12px"}),n(o,{width:"90%",height:"10px"}),n(o,{width:"75%",height:"10px"}),n("div",{style:{height:"8px"}}),n(o,{width:"40%",height:"12px"}),n(o,{width:"100%",height:"10px"}),n(o,{width:"80%",height:"10px"}),n("div",{style:{height:"8px"}}),n(o,{width:"55%",height:"12px"}),n(o,{width:"95%",height:"10px"}),n(o,{width:"70%",height:"10px"}),n(o,{width:"45%",height:"12px"}),n(o,{width:"88%",height:"10px"})]}))},h=function(o){return o.isLoading?t(e,{children:[n("style",{children:"\n @keyframes shimmer {\n 0% {\n background-position: -200px 0;\n }\n 100% {\n background-position: calc(200px + 100%) 0;\n }\n }\n"}),n("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:99}}),t("div",i({style:{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",backgroundColor:"#fff",borderRadius:"16px",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",padding:"48px",maxWidth:"1000px",width:"70%",maxHeight:"90vh",display:"flex",flexDirection:"row",gap:"48px",zIndex:100,animation:"fadeIn 0.3s ease-out"}},{children:[t("div",i({style:{flex:1,display:"flex",flexDirection:"column",justifyContent:"center"}},{children:[n("div",i({style:{marginBottom:"16px"}},{children:n(r,{size:32,color:"#7C3AED"})})),n("h2",i({style:{fontSize:"1.5rem",fontWeight:600,color:"#0F172A",margin:"0 0 8px 0"}},{children:"Setting up your scope…"})),n("p",i({style:{fontSize:"0.875rem",color:"#64748B",margin:"0",lineHeight:"1.5"}},{children:"Inheriting Learnings from Global. This will only take a moment."}))]})),n("div",i({style:{flex:1.5,display:"flex",alignItems:"center",justifyContent:"center",minWidth:"350px"}},{children:n(d,{})}))]})),n("style",{children:"\n @keyframes fadeIn {\n from {\n opacity: 0;\n transform: translate(-50%, -48%);\n }\n to {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n }\n "})]}):null};export{h as default};
|
|
2
|
+
//# sourceMappingURL=ScopeSkeletonLoader.js.map
|