@viswa-test/test-citation 0.0.312 → 0.0.314

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.
Files changed (57) hide show
  1. package/dist/cjs/features/CognitiveCompare/CognitiveCompare.js +1 -1
  2. package/dist/cjs/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
  3. package/dist/cjs/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
  4. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/guidelineTargets.js +2 -0
  5. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/guidelineTargets.js.map +1 -0
  6. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
  7. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.js +2 -0
  8. package/dist/cjs/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.js.map +1 -0
  9. package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js +1 -1
  10. package/dist/cjs/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
  11. package/dist/cjs/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
  12. package/dist/cjs/features/PdfViewer/PdfStyle.js +1 -1
  13. package/dist/cjs/features/PdfViewer/PdfViewer.js +1 -1
  14. package/dist/cjs/features/SegmentReviewComponents/LabelCheck.js +1 -1
  15. package/dist/cjs/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js +1 -1
  16. package/dist/features/CognitiveCompare/CognitiveCompare.js +1 -1
  17. package/dist/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
  18. package/dist/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
  19. package/dist/features/CognitiveCompare/Guidelines/utils/guidelineTargets.js +2 -0
  20. package/dist/features/CognitiveCompare/Guidelines/utils/guidelineTargets.js.map +1 -0
  21. package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
  22. package/dist/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.js +2 -0
  23. package/dist/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.js.map +1 -0
  24. package/dist/features/CognitiveCompare/hooks/useCompareData.js +1 -1
  25. package/dist/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
  26. package/dist/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
  27. package/dist/features/PdfViewer/PdfStyle.js +1 -1
  28. package/dist/features/PdfViewer/PdfViewer.js +1 -1
  29. package/dist/features/SegmentReviewComponents/LabelCheck.js +1 -1
  30. package/dist/features/SegmentReviewComponents/SegmentReviewPdfWrapper.js +1 -1
  31. package/dist/types/src/features/CognitiveCompare/CognitiveCompare.d.ts +1 -1
  32. package/dist/types/src/features/CognitiveCompare/CognitiveCompare.d.ts.map +1 -1
  33. package/dist/types/src/features/CognitiveCompare/CognitiveCompareTypes.d.ts +1 -1
  34. package/dist/types/src/features/CognitiveCompare/CognitiveCompareTypes.d.ts.map +1 -1
  35. package/dist/types/src/features/CognitiveCompare/Guidelines/components/GuidelinePanel.d.ts.map +1 -1
  36. package/dist/types/src/features/CognitiveCompare/Guidelines/components/WebGptPanel.d.ts.map +1 -1
  37. package/dist/types/src/features/CognitiveCompare/Guidelines/constants/guidelines.mockData.d.ts +14771 -829
  38. package/dist/types/src/features/CognitiveCompare/Guidelines/constants/guidelines.mockData.d.ts.map +1 -1
  39. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/guidelineTargets.d.ts +3 -0
  40. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/guidelineTargets.d.ts.map +1 -0
  41. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts +14 -1
  42. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts.map +1 -1
  43. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.d.ts +19 -0
  44. package/dist/types/src/features/CognitiveCompare/Guidelines/utils/resolveGuidelineSelection.d.ts.map +1 -0
  45. package/dist/types/src/features/CognitiveCompare/hooks/useCompareData.d.ts +1 -1
  46. package/dist/types/src/features/CognitiveCompare/hooks/useCompareData.d.ts.map +1 -1
  47. package/dist/types/src/features/CognitiveCompare/hooks/useLinesCalculator.d.ts.map +1 -1
  48. package/dist/types/src/features/CognitiveCompare/hooks/useSideBySide.d.ts.map +1 -1
  49. package/dist/types/src/features/PdfViewer/PdfStyle.d.ts.map +1 -1
  50. package/dist/types/src/features/PdfViewer/PdfViewer.d.ts +7 -1
  51. package/dist/types/src/features/PdfViewer/PdfViewer.d.ts.map +1 -1
  52. package/dist/types/src/features/SegmentReviewComponents/LabelCheck.d.ts +6 -1
  53. package/dist/types/src/features/SegmentReviewComponents/LabelCheck.d.ts.map +1 -1
  54. package/dist/types/src/features/SegmentReviewComponents/SegmentReviewPdfWrapper.d.ts +3 -1
  55. package/dist/types/src/features/SegmentReviewComponents/SegmentReviewPdfWrapper.d.ts.map +1 -1
  56. package/dist/types/src/features/SegmentReviewComponents/SegmentReviewRedirectionTest.d.ts.map +1 -1
  57. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),i=require("react"),t=require("@mui/material"),o=require("lucide-react"),r=require("../../assests/svg/ButtonCognitiveIcon.js"),l=require("./OverlayComponent.js"),u=require("./CognitiveComparehelpers.js"),s=require("./CognitiveCompareConfig.js"),a=require("./CognitiveCompareConstants.js"),c=require("./CognitivePopup.js"),d=require("./MoreFunctionsPopup.js"),f=require("./LoaderComponent.js"),v=require("./components/ThreeDotsLoader.js"),g=require("./hooks/useCompareData.js"),p=require("./hooks/useComparePopups.js"),h=require("./hooks/useSectionRefs.js"),m=require("./hooks/useAccordionState.js"),S=require("./hooks/useDeviationNavigation.js"),R=require("./components/CompareHeader.js"),x=require("./components/SubSectionAccordion.js"),_=require("./components/LHSSectionRow.js"),b=require("./components/RHSSectionRow.js"),y=require("./components/CognitiveSummaryPopup.js"),C=require("./CompareContext.js"),E=require("./hooks/useStyles.js"),A=require("./hooks/useResizeHandler.js"),T=require("./hooks/useLinesCalculator.js"),w=require("./hooks/useSideBySide.js"),I=require("./components/SvgConnectors.js"),B=require("./Guidelines/components/GuidelinePanel.js"),D=require("./Guidelines/components/WebGptPanel.js");exports.SHARED_MARKDOWN_STYLES=s.SHARED_MARKDOWN_STYLES,exports.default=function(O){var F,j,P,k,N,M,L,q,H,G,V,W,z,K,U,Y,J,X,$,Q,Z,ee,ne,ie,te,oe,re,le,ue,se,ae,ce,de,fe,ve,ge=O.componentHeaderText,pe=void 0===ge?a.DEFAULT_COMPONENT_HEADER_TEXT:ge,he=O.treeData,me=O.comparisonConfig,Se=O.leftColumnTitleText,Re=O.rightColumnTitleText,xe=O.markdownStyles,_e=O.resetTrigger,be=O.displayConfig,ye=void 0===be?{isHeaderVisible:!0,isToggleVisible:!0,maintainRelativeOrder:!1,isLoading:!0,showDeviationBadges:!1,enableDeviationSchemaBackwardCompatibility:!1,displayEmailNotifier:!0,isStreamingEnabled:!1}:be,Ce=O.onMaintainRelativeOrderChange,Ee=O.popupConfig,Ae=O.deviationData,Te=void 0===Ae?{}:Ae,we=O.deviationNodeIdToView,Ie=O.resetDeviationNodeId,Be=O.isProposingFix,De=void 0!==Be&&Be,Oe=O.proposingFixNodeId,Fe=O.isRedlineFlow,je=O.badgeStyleOverride,Pe=O.guidelinesData,ke=O.gptWebCitationConfig,Ne=i.useState(ye.maintainRelativeOrder),Me=Ne[0],Le=Ne[1],qe=null!==(F=null==ye?void 0:ye.expandLevels)&&void 0!==F?F:0,He=!!(null==ye?void 0:ye.expandAllSections),Ge=!!Me||!!(null==ye?void 0:ye.showDeviationBadges),Ve=i.useState(!1),We=Ve[0],ze=Ve[1],Ke=i.useState(null),Ue=Ke[0],Ye=Ke[1],Je=i.useState(null===(P=null!==(j=null==he?void 0:he.newEvaluationResult)&&void 0!==j?j:null==ye?void 0:ye.enableDeviationSchemaBackwardCompatibility)||void 0===P||P)[0],Xe=i.useState(new Set),$e=Xe[0],Qe=Xe[1],Ze=i.useState([]),en=Ze[0],nn=Ze[1],tn=i.useState(!1),on=tn[0],rn=tn[1],ln=i.useState(0),un=ln[0],sn=ln[1],an=i.useRef(null),cn=i.useRef(null),dn=i.useRef(null),fn=i.useRef(null),vn=i.useRef(null),gn=i.useRef(!1),pn=i.useRef(null),hn=i.useRef({}),mn=i.useRef([]),Sn=i.useRef(function(){}),Rn=i.useRef(null),xn=i.useRef(function(){}),_n=i.useMemo(function(){return JSON.stringify(Te||{})},[JSON.stringify(Te)]),bn=i.useMemo(function(){return Te||{}},[_n]),yn=i.useMemo(function(){return(null==he?void 0:he.cognitive_decisioning)||{}},[he]),Cn=i.useMemo(function(){return e.__assign(e.__assign({},s.SHARED_MARKDOWN_STYLES),xe)},[xe]),En=i.useRef(null),An=i.useRef(null),Tn=i.useRef(null),wn=i.useRef(null),In=i.useRef(null),Bn=i.useRef(null),Dn=i.useRef(null),On=i.useRef(null),Fn=i.useRef(null),jn=i.useRef(null),Pn=p.useComparePopups(En),kn=Pn.cognitivePopup,Nn=Pn.setCognitivePopup,Mn=Pn.moreFunctions,Ln=Pn.setMoreFunctions,qn=Pn.position,Hn=Pn.setPosition,Gn=Pn.activeBadgeId,Vn=Pn.summaryPopup,Wn=Pn.setSummaryPopup,zn=Pn.closeSummaryPopup,Kn=Pn.setActiveBadgeId,Un=Pn.popupRef,Yn=Pn.handleOpenCognitiveCompare,Jn=Pn.openCognitivePopupFromState,Xn=Pn.closeCognitivePopup,$n=Pn.closeMoreFunctionsPopup,Qn=i.useMemo(function(){var e,n,i,t,o,r,l;return{fields:null!==(e=null==me?void 0:me.fields)&&void 0!==e?e:s.DEFAULT_FIELD_CONFIG,thresholds:{high:null!==(i=null===(n=null==me?void 0:me.thresholds)||void 0===n?void 0:n.high)&&void 0!==i?i:s.DEFAULT_COMPARISON_CONFIG.thresholds.high,medium:null!==(o=null===(t=null==me?void 0:me.thresholds)||void 0===t?void 0:t.medium)&&void 0!==o?o:s.DEFAULT_COMPARISON_CONFIG.thresholds.medium,exact:null!==(l=null===(r=null==me?void 0:me.thresholds)||void 0===r?void 0:r.exact)&&void 0!==l?l:s.DEFAULT_COMPARISON_CONFIG.thresholds.exact}}},[me]),Zn=i.useState(null),ei=Zn[0];Zn[1];var ni=null===(M=null===(k=null==he?void 0:he.documents)||void 0===k?void 0:k[null===(N=null==he?void 0:he.input_index_map)||void 0===N?void 0:N[0]])||void 0===M?void 0:M.title,ii=null===(H=null===(L=null==he?void 0:he.documents)||void 0===L?void 0:L[null===(q=null==he?void 0:he.input_index_map)||void 0===q?void 0:q[1]])||void 0===H?void 0:H.title,ti=u.safeStringify(Se||ni||"Uploaded Contract"),oi=null===(z=null===(W=null===(G=null==he?void 0:he.documents)||void 0===G?void 0:G[null===(V=null==he?void 0:he.input_index_map)||void 0===V?void 0:V[0]])||void 0===W?void 0:W.metadata)||void 0===z?void 0:z.file_name,ri=u.safeStringify(oi),li=null===(J=null===(Y=null===(K=null==he?void 0:he.documents)||void 0===K?void 0:K[null===(U=null==he?void 0:he.input_index_map)||void 0===U?void 0:U[1]])||void 0===Y?void 0:Y.metadata)||void 0===J?void 0:J.file_name,ui=u.safeStringify(li),si=u.safeStringify(Re||ii||"Reference Template"),ai=g.useCognitiveTreeData(he,Me,bn,Qn,Je,Pe),ci=ai.isGuidelineMode,di=ai.activeProposed,fi=ai.existingRule,vi=ai.proposedSections,gi=ai.existingSections,pi=ai.visibleFields,hi=ai.parentDeviationRecord,mi=ai.deviationNumberRegistry,Si=ai.deviationParentRegistry,Ri=ai.parseError;i.useEffect(function(){Ri&&Ye("Failed to load comparison: ".concat(Ri))},[Ri]);var xi=vi.length>0||gi.length>0,_i=i.useMemo(function(){if(!Fe)return"off";var e=0,n=0,i=function(t){Array.isArray(t)&&t.forEach(function(t){var o,r=(null==t?void 0:t.content)||"";u.hasMeaningfulRedlineTags(r)&&(e+=1,n+=String(r).length),(null===(o=null==t?void 0:t.subsections)||void 0===o?void 0:o.length)&&i(t.subsections)})};return i(vi),i(gi),"".concat(e,":").concat(n)},[Fe,vi,gi]);i.useEffect(function(){if(vi.length||gi.length)if(He){var e={},n={},i=function(i,t){i.forEach(function(i,o){var r,l=Me?"".concat(t,"-").concat(o):String(o);e[l]=!0;var u=function(e,i){null==e||e.forEach(function(e,t){var o,r="".concat(i,"-").concat(t);n[r]=!0,(null===(o=e.subsections)||void 0===o?void 0:o.length)&&u(e.subsections,r)})};(null===(r=i.subsections)||void 0===r?void 0:r.length)&&u(i.subsections,String(o))})};i(vi,"left"),i(gi,"right"),tt(e),rt(n)}else if(qe>0){var t={},o={},r=function(e,n,i){e.forEach(function(e,r){var l;if(i>=1){var u=Me?"".concat(n,"-").concat(r):String(r);t[u]=!0}var s=function(e,n,t){t>i||null==e||e.forEach(function(e,i){var r,l="".concat(n,"-").concat(i);o[l]=!0,(null===(r=e.subsections)||void 0===r?void 0:r.length)&&s(e.subsections,l,t+1)})};(null===(l=e.subsections)||void 0===l?void 0:l.length)&&i>=2&&s(e.subsections,String(r),2)})};r(vi,"left",qe),r(gi,"right",qe),tt(t),rt(o)}},[He,qe,vi,gi,Me]);var bi=h.useSectionRefs(pi.map(function(e){return e.key}),Math.max(vi.length,gi.length)),yi=bi.leftRefs,Ci=bi.rightRefs,Ei=bi.sectionLeftRefs,Ai=bi.sectionRightRefs,Ti=bi.lhsBadgeRefs,wi=bi.rhsBadgeRefs,Ii=bi.sectionRightRowRefs,Bi=bi.subSectionLeftRefs,Di=bi.subSectionRightRefs,Oi=bi.sectionRowRefs,Fi=bi.getSectionRowRef,ji=bi.getSubSectionRef,Pi=bi.getBadgeRef,ki=w.useSideBySide({isGuidelineMode:ci,maintainRelativeOrder:Me,proposedSections:vi,existingSections:gi,leftContainerRef:On,rightContainerRef:Tn,scrollContainerRef:En,sectionLeftRefs:Ei,sectionRightRefs:Ai,subSectionLeftRefs:Bi,subSectionRightRefs:Di,lhsBadgeRefs:Ti,rhsBadgeRefs:wi,sectionRowRefs:Oi,sectionRightRowRefs:Ii,rhsTopSpacerRef:wn,rhsBottomSpacerRef:In,lhsTopSpacerRef:Bn,lhsBottomSpacerRef:Dn,calculateLinesRef:Sn,setConnectedSections:Qe,setConnectedLines:nn,cachedConnectedPositions:mn,closeMoreFunctionsPopup:$n,setErrorToast:Ye,moreFunctions:Mn,closeSummaryPopup:zn}),Ni=ki.isSideBySide,Mi=ki.isArrowVisible,Li=ki.setIsArrowVisible,qi=ki.isResizing,Hi=ki.setIsResizing,Gi=ki.isSideBySideLoading,Vi=ki.activeSideBySideSection,Wi=ki.scrollLock,zi=ki.sideBySideCacheRef,Ki=ki.isSideBySideRef,Ui=ki.activeSideBySideRightSectionRef,Yi=ki.activeSideBySideSectionRef,Ji=ki.sideBySideLineRef,Xi=ki.highlightedClauseRefs,$i=ki.clearClauseHighlight,Qi=ki.resetSideBySide,Zi=ki.activateSideBySide,et=i.useRef(Zi);i.useEffect(function(){et.current=Zi},[Zi]);var nt=m.useAccordionState({maintainRelativeOrder:!!Me,proposedSections:vi,existingSections:gi,activeSideBySideSection:Vi,connectedSections:$e,resetSideBySide:Qi,setConnectedSections:Qe,setConnectedLines:nn,cachedConnectedPositions:mn,svgContainerRef:an,isAnimatingRef:gn,animationTimerRef:pn,calculateLinesRef:Sn,sectionLeftRefs:Ei,sectionRightRefs:Ai,subSectionLeftRefs:Bi,subSectionRightRefs:Di}),it=nt.expandedSections,tt=nt.setExpandedSections,ot=nt.expandedSubSections,rt=nt.setExpandedSubSections,lt=nt.handleSubSectionToggle,ut=nt.toggleSection,st=nt.forceExpandCrossWiredSections,at=function(){var e,n;if(null!=Vi){var i=null===(e=Ei.current[Vi])||void 0===e?void 0:e.current,t=null===(n=Ai.current[Vi])||void 0===n?void 0:n.current,o=Tn.current;if(i&&t&&o){var r=i.getBoundingClientRect(),l=t.getBoundingClientRect(),u=o.getBoundingClientRect(),s=r.top-u.top,a=l.top-u.top-s;o.scrollBy({top:a,behavior:"smooth"})}}},ct=i.useCallback(function(e){null==e||e.stopPropagation(),rn(function(e){var n=!e;return n&&requestAnimationFrame(function(){at()}),n})},[at]);i.useEffect(function(){Fe&&"off"!==_i&&"0:0"!==_i&&(zi.current=null,mn.current=[],requestAnimationFrame(function(){var e;null===(e=Sn.current)||void 0===e||e.call(Sn)}))},[Fe,_i]);var dt=i.useMemo(function(){var e=new Map,n=new Map,i=1;if(Me)vi.forEach(function(n){!n.title&&!n.content||n.id&&e.set(n.id,i++)}),gi.forEach(function(t){if(t.id&&!(!t.title&&!t.content)){var o=vi.filter(function(e){var n;return null===(n=e.refIndexes)||void 0===n?void 0:n.includes(t.selfIndex)});if(o.length>0){var r=o.map(function(n){return e.get(n.id)}).filter(Boolean);n.set(t.id,r.join(", "))}else n.set(t.id,String(i++))}});else for(var t=Math.max(vi.length,gi.length),o=0;o<t;o++){var r=vi[o],l=gi[o];r?(e.set(r.id,i),l&&n.set(l.id,String(i)),i++):l&&n.set(l.id,String(i++))}return{leftNums:e,rightNums:n}},[vi,gi,Me]),ft=fi.analysis,vt=u.safeStringify(null===($=null===(X=null==ft?void 0:ft.rule_difference_comparison)||void 0===X?void 0:X.summary)||void 0===$?void 0:$.overall_summary),gt=!!vt.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),pt=null!==(Q=null==he?void 0:he.base_root_id)&&void 0!==Q?Q:"-1";null==he||he[pt];var ht=Je?null!==(ce=null!==(ue=Te&&(null===(le=null==Te?void 0:Te[pt])||void 0===le?void 0:le.evaluation_result))&&void 0!==ue?ue:null===(ae=null===(se=null==he?void 0:he.nodes)||void 0===se?void 0:se[pt])||void 0===ae?void 0:ae.evaluation_result)&&void 0!==ce?ce:null:null!==(re=null!==(ne=Te&&(null===(ee=null===(Z=null==Te?void 0:Te[pt])||void 0===Z?void 0:Z.evaluation_result)||void 0===ee?void 0:ee[0]))&&void 0!==ne?ne:null===(oe=null===(te=null===(ie=null==he?void 0:he.nodes)||void 0===ie?void 0:ie[pt])||void 0===te?void 0:te.evaluation_result)||void 0===oe?void 0:oe[0])&&void 0!==re?re:null,mt=u.extractDeviationScore(ht),St=u.generateColorPalette(null!==(ve=null===(fe=null===(de=null==ht?void 0:ht.evaluation_outputs)||void 0===de?void 0:de.metadata)||void 0===fe?void 0:fe.label_color)&&void 0!==ve?ve:a.DEFAULT_DEVIAION_COLOR);if(je){var Rt=je(mt);Rt&&(St=e.__assign(e.__assign({},St),{badgeBg:Rt.bg,badgeText:Rt.text,badgeBorder:Rt.border}))}var xt=i.useRef(Qi);i.useEffect(function(){xt.current=Qi},[Qi]);var _t=i.useRef(Xn);i.useEffect(function(){_t.current=Xn},[Xn]);var bt=i.useCallback(function(e,n,i,t,o,r){return Oo.current(e,n,i,t,o,r)},[]),yt=i.useCallback(function(e,n,i,t,o){return jo.current(e,n,i,t,o)},[]),Ct=i.useCallback(function(){return Po.current()},[]),Et=i.useCallback(function(e,n){return ko.current(e,n)},[]),At=i.useCallback(function(e){return No.current(e)},[]),Tt=i.useCallback(function(e){return Mo.current(e)},[]),wt=i.useCallback(function(){return Lo.current()},[]),It=i.useCallback(function(){var e,n;$i(),null===(e=xt.current)||void 0===e||e.call(xt),rn(!1),Qe(new Set),nn([]),mn.current=[],$t([]),Zt(null),Wn(a.EMPTY_SUMMARY_POPUP_STATE),null===(n=_t.current)||void 0===n||n.call(_t),requestAnimationFrame(function(){var e;null===(e=Sn.current)||void 0===e||e.call(Sn)})},[]),Bt=i.useRef(It);i.useEffect(function(){Bt.current=It},[It]),i.useEffect(function(){_e&&Bt.current()},[_e]);var Dt=i.useMemo(function(){return{documents:null==he?void 0:he.documents,input_index_map:null==he?void 0:he.input_index_map}},[JSON.stringify(null==he?void 0:he.documents),JSON.stringify(null==he?void 0:he.input_index_map)]),Ot=i.useState(""),Ft=Ot[0],jt=Ot[1],Pt=i.useRef(he);i.useEffect(function(){var e,n,i;Pt.current=he;var t=null===(e=null==he?void 0:he.input_index_map)||void 0===e?void 0:e[0],o=null===(i=null===(n=null==he?void 0:he.documents)||void 0===n?void 0:n[t])||void 0===i?void 0:i.title;jt(o)},[he]);var kt=i.useRef(yn);i.useEffect(function(){kt.current=yn},[yn]);var Nt=i.useCallback(function(n,i,t,o,r,l,s){var a,c,d,f,v,g,p,h,m,S,R=u.safeStringify(null==i?void 0:i.id)||u.safeStringify(null==t?void 0:t.id)||"",x=(R?null===(a=kt.current)||void 0===a?void 0:a[R]:null)||(null==i?void 0:i.cognitiveData)||(null==t?void 0:t.cognitiveData)||{section_id:R,decisioning:[],gap:[],relevance_score:0},_=null!==(d=null===(c=Oi.current[o])||void 0===c?void 0:c.current)&&void 0!==d?d:null,b=function(){var n,r,l=(null==i?void 0:i.evaluationResult)||(null==t?void 0:t.evaluationResult)||null,s=function(n){var i=function(e){if(!e||"object"!=typeof e)return null;var n=null==e?void 0:e.deviation_entries;if(n&&"object"==typeof n){var i=Object.keys(n).sort(function(e,n){return Number(e)-Number(n)})[0];if(i&&n[i])return n[i]}var t=Object.keys(e).filter(function(e){return/^\d+$/.test(e)}).sort(function(e,n){return Number(e)-Number(n)});if(t.length&&e[t[0]])return e[t[0]];var o=null==e?void 0:e.deviations;if(o&&"object"==typeof o){var r=Object.keys(o).sort(function(e,n){return Number(e)-Number(n)})[0];if(r&&o[r])return o[r]}return null}(n);return i?e.__assign(e.__assign({},n),{deviation_summary:(null==n?void 0:n.deviation_summary)||(null==i?void 0:i.deviation_summary),deviation_title:(null==n?void 0:n.deviation_title)||(null==i?void 0:i.deviation_title),deviation_impact:(null==n?void 0:n.deviation_impact)||(null==i?void 0:i.deviation_impact),deviation_explanation:(null==n?void 0:n.deviation_explanation)||(null==i?void 0:i.deviation_explanation),evaluation_outputs:(null==n?void 0:n.evaluation_outputs)||(null==i?void 0:i.evaluation_outputs),cognitive_decisioning:(null==n?void 0:n.cognitive_decisioning)||(null==i?void 0:i.cognitive_decisioning)}):n};if(!("string"==typeof o&&o.includes(u.DEVIATION_BADGE_SEPARATOR)))return s(l);var a=o.split(u.DEVIATION_BADGE_SEPARATOR)[1];if(!a)return l;var c=(null==i?void 0:i.evaluationResult)||(null==t?void 0:t.evaluationResult)||{},d=(null===(n=null==c?void 0:c.deviation_entries)||void 0===n?void 0:n[a])||(null===(r=null==c?void 0:c.deviations)||void 0===r?void 0:r[a])||null;return d?e.__assign(e.__assign(e.__assign({},c),d),{deviation_summary:(null==d?void 0:d.deviation_summary)||(null==c?void 0:c.deviation_summary),deviation_title:(null==d?void 0:d.deviation_title)||(null==c?void 0:c.deviation_title),deviation_impact:(null==d?void 0:d.deviation_impact)||(null==c?void 0:c.deviation_impact),deviation_explanation:(null==d?void 0:d.deviation_explanation)||(null==c?void 0:c.deviation_explanation),evaluation_outputs:(null==d?void 0:d.evaluation_outputs)||(null==c?void 0:c.evaluation_outputs),cognitive_decisioning:(null==d?void 0:d.cognitive_decisioning)||(null==c?void 0:c.cognitive_decisioning)}):s(l)}(),y=(null!==(g=null===(v=null===(f=null==b?void 0:b.cognitive_decisioning)||void 0===f?void 0:f.decisioning_factors)||void 0===v?void 0:v.length)&&void 0!==g?g:0)>0||(null!==(m=null===(h=null===(p=null==b?void 0:b.cognitive_decisioning)||void 0===p?void 0:p.gaps_in_decision)||void 0===h?void 0:h.length)&&void 0!==m?m:0)>0,C=null!==(S=null==ye?void 0:ye.isLoading)&&void 0!==S&&S,E=!0;if(ci){var A=null==b?void 0:b.deviation_highlights;if(A&&"object"==typeof A)E=Object.values(A).some(function(e){return Array.isArray(e)&&e.length>0});else E=!1}return{isLoading:C&&!y,open:!0,sectionTitle:(null==i?void 0:i.title)?null==i?void 0:i.title:"No Counterpart",refSectionTitle:(null==t?void 0:t.title)?null==t?void 0:t.title:"No Counterpart",cognitiveData:x,anchorEl:n,sectionAnchorEl:_,badgeStyle:l||null,sectionIdx:o,docData:Dt,deviationData:b,isOrphan:!!r,hasGuidelineMatches:E}},[Dt,null==ye?void 0:ye.isLoading,ci]),Mt=i.useCallback(function(e,n,i,t,o,r){var l;if(e.stopPropagation(),Mn.open&&Mn.sectionIdx===o)$n();else{var s=e.currentTarget,a="left";(null===(l=Tn.current)||void 0===l?void 0:l.contains(s))&&(a="right");$i(),Ki.current&&Qi(),Qe(new Set),nn([]),mn.current=[],Xn(),Vn.open?vo():zn(),requestAnimationFrame(function(){var e=function(){var e,n,i,t;if("string"==typeof o&&o.includes(u.DEVIATION_BADGE_SEPARATOR)){var r=o.split(u.DEVIATION_BADGE_SEPARATOR),l="".concat(r[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(r[1]);return"right"===a?null===(e=wi.current[l])||void 0===e?void 0:e.current:null===(n=Ti.current[l])||void 0===n?void 0:n.current}return"right"===a?null===(i=wi.current[o])||void 0===i?void 0:i.current:null===(t=Ti.current[o])||void 0===t?void 0:t.current}()||s;Ln(Nt(e,n,t,o,i,r))})}},[Mn.open,Mn.sectionIdx,$n,zn,Nt]),Lt=i.useCallback(function(){var e=Mn.sectionIdx;Mn.isOrphan,$n(),zn(),null!==e&&(st(e),$i(),Ki.current&&Qi(),nn([]),mn.current=[],ci&&null!==e&&sn(ao(e)),Qe(function(n){return n.has(e)?new Set:new Set([e])}),setTimeout(function(){Sn.current&&Sn.current()},50))},[Mn.sectionIdx,Mn.isOrphan,$n,zn,Qi]),qt=i.useCallback(function(){var e=vn.current;if(e){vn.current=null;var n=vi.findIndex(function(n){return n.id===e}),i=gi.findIndex(function(n){return n.id===e}),t=-1===n?u.findKeyPathByNodeId(vi,e):null,o=-1===i?u.findKeyPathByNodeId(gi,e):null,r=-1!==n?n:t?Number(t.split("-")[0]):-1,l=-1!==i?i:o?Number(o.split("-")[0]):-1,s=function(e,n,i,t){var o,r,l,u;return-1!==e?null!==(r=null===(o=i.current[e])||void 0===o?void 0:o.current)&&void 0!==r?r:null:n&&null!==(u=null===(l=t.current[n])||void 0===l?void 0:l.current)&&void 0!==u?u:null},a=function(e,n,i){void 0===i&&(i=30);var t=0,o=function(){var r=e();r&&0!==r.getBoundingClientRect().height?(Xi.current.add(r),u.scrollAndHighlightClause(r,n)):t++<i&&requestAnimationFrame(o)};requestAnimationFrame(o)};if(Me)-1!==r&&On.current&&a(function(){return s(n,t,Ei,Bi)},On.current),-1!==l&&Tn.current&&a(function(){return s(i,o,Ai,Di)},Tn.current);else{var c=En.current;if(!c)return;a(function(){return-1!==r?s(n,t,Ei,Bi):s(i,o,Ai,Di)},c)}}},[vi,gi,Me,Ei,Ai,Bi,Di,On,Tn,En]),Ht=i.useCallback(function(n){if(n){$i(),Qi(),Qe(new Set),nn([]),mn.current=[],zn(),Xn();var i=vi.findIndex(function(e){return e.id===n}),t=gi.findIndex(function(e){return e.id===n}),o=-1===i?u.findKeyPathByNodeId(vi,n):null,r=-1===t?u.findKeyPathByNodeId(gi,n):null;if(-1!==i||o||-1!==t||r){var l=-1!==i?i:o?Number(o.split("-")[0]):-1,s=-1!==t?t:r?Number(r.split("-")[0]):-1;vn.current=n,tt(function(n){var i,t=e.__assign({},n),o=!1;-1!==l&&(t[i=Me?"left-".concat(l):String(l)]||(t[i]=!0,o=!0));-1!==s&&(t[i=Me?"right-".concat(s):String(s)]||(t[i]=!0,o=!0));return o?t:n}),rt(function(n){var i=e.__assign({},n),t=!1,l=function(e){for(var n=e.split("-"),o=n[0],r=1;r<n.length;r++)o+="-".concat(n[r]),i[o]||(i[o]=!0,t=!0)};return o&&l(o),r&&l(r),t?i:n}),setTimeout(function(){requestAnimationFrame(function(){vn.current===n&&Gt.current()})},50)}else console.warn('scrollToAndHighlightClause: nodeId "'.concat(n,'" not found'))}},[vi,gi,Me,tt,rt,Qi,zn,Xn]),Gt=i.useRef(qt);i.useEffect(function(){Gt.current=qt},[qt]);var Vt=i.useRef(null);i.useEffect(function(){if(ei){var e=Qn.fields.find(function(e){return e.analysisKey===ei||e.key===ei});if(e){var n=yi.current[e.key]||Ci.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[ei,Qn.fields]);var Wt=i.useCallback(function(e){var n,i,t,o,r,l,u,s,a,c=null===(n=null==ft?void 0:ft.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!c||!c[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var d=c[e],f=(null==d?void 0:d.relation)||(null===(t=null===(i=null==d?void 0:d.highlights)||void 0===i?void 0:i.ruleA_spans)||void 0===t?void 0:t.length)||(null===(r=null===(o=null==d?void 0:d.highlights)||void 0===o?void 0:o.ruleB_spans)||void 0===r?void 0:r.length)||(null==d?void 0:d.mappings)&&d.mappings.length>0;if(d.mappings){var v=d.mappings[0]||{};return{score:d.score,relation:v.relation||"",highlightsA:(null===(l=v.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(u=v.highlights)||void 0===u?void 0:u.ruleB_spans)||[],hasContent:!!f}}return{score:d.score,relation:d.relation||"",highlightsA:(null===(s=d.highlights)||void 0===s?void 0:s.ruleA_spans)||[],highlightsB:(null===(a=d.highlights)||void 0===a?void 0:a.ruleB_spans)||[],hasContent:!!f}},[ft]),zt=E.useStyleHelpers({proposedSections:vi,existingSections:gi,maintainRelativeOrder:Me,cognitiveMap:yn,deviationData:bn,treeData:he,resolvedComparisonConfig:Qn,badgeStyleOverride:je}),Kt=zt.getSectionCompareStyle,Ut=zt.getSubSectionCompareStyle,Yt=zt.getDeviationStyleByKey,Jt=T.useLinesCalculator({containerRef:cn,leftContainerRef:On,rightContainerRef:Tn,svgContainerRef:an,pathRefs:hn,leftHeaderRef:dn,rightHeaderRef:fn,proposedSections:vi,existingSections:gi,visibleFields:pi,leftRefs:yi,rightRefs:Ci,sectionLeftRefs:Ei,sectionRightRefs:Ai,subSectionLeftRefs:Bi,subSectionRightRefs:Di,lhsBadgeRefs:Ti,rhsBadgeRefs:wi,sectionRowRefs:Oi,expandedSections:it,expandedSubSections:ot,connectedSections:$e,isSideBySide:Ni,activeSideBySideSection:Vi,maintainRelativeOrder:Me,isGuidelineMode:ci,cognitiveMap:yn,getSectionCompareStyle:Kt,getSubSectionCompareStyle:Ut,getDeviationStyleByKey:Yt,isArrowVisible:Mi,isAnimatingRef:gn,isSideBySideRef:Ki,sideBySideCacheRef:zi,sideBySideLineRef:Ji,activeSideBySideSectionRef:Yi,activeSideBySideRightSectionRef:Ui,connectedLines:en,setConnectedLines:nn,cachedConnectedPositions:mn,calculateLinesRef:Sn,resizeTimerRef:Rn,scrollLock:Wi,scrollSyncLocked:on,handleResizeRef:xn,activeProposed:di,existingRule:fi,analysisData:ft,pendingScrollTargetRef:Fn,pendingScrollCallbackRef:jn,resolvedComparisonConfig:Qn,getFieldData:Wt}),Xt=Jt.lines,$t=Jt.setLines,Qt=Jt.overallConnector,Zt=Jt.setOverallConnector,eo=Jt.svgDimensions,no=Jt.handleColumnScroll;i.useEffect(function(){Vn.anchorEl&&requestAnimationFrame(function(){requestAnimationFrame(function(){var e;null===(e=Sn.current)||void 0===e||e.call(Sn)})})},[Vn.anchorEl,on]);var io=i.useCallback(function(){$i(),rn(!1),tt({}),rt({}),Qi(),Qe(new Set),nn([]),mn.current=[],zn(),Xn(),$n(),requestAnimationFrame(function(){Sn.current&&Sn.current()})},[tt,rt,Qi,zn,Xn,$n]);i.useEffect(function(){Ni||0!==$e.size||rn(!1)},[Ni,$e]);var to=i.useMemo(function(){return Object.values(it).some(Boolean)||Object.values(ot).some(Boolean)},[it,ot]),oo=i.useRef(null),ro=i.useRef(0),lo=i.useRef(0),uo=i.useRef(0),so=A.useResizeHandler({timerRef:oo,ruleComponentRef:An,scrollContainerRef:En,containerRef:cn,maintainRelativeOrder:Me,proposedSections:vi,existingSections:gi,isSideBySideRef:Ki,activeSideBySideSectionRef:Yi,activeSideBySideRightSectionRef:Ui,sectionRowRefs:Oi,sectionRightRowRefs:Ii,sectionLeftRefs:Ei,sectionRightRefs:Ai,subSectionLeftRefs:Bi,subSectionRightRefs:Di,lhsBadgeRefs:Ti,rhsBadgeRefs:wi,leftContainerRef:On,rightContainerRef:Tn,calculateLinesRef:Sn,handleResizeRef:xn,setIsResizing:Hi,setIsArrowVisible:Li,sideBySideCacheRef:zi,cachedConnectedPositions:mn}).handleResize;i.useEffect(function(){xn.current=so},[so,xn]),i.useEffect(function(){var e=function(e,n,i,t,o){n.current=e.getBoundingClientRect().width;var r=new ResizeObserver(function(e){null!==i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(function(){var r,l,u;i.current=null;var s=e[e.length-1];if(s){var a=null!==(u=null===(l=null===(r=s.borderBoxSize)||void 0===r?void 0:r[0])||void 0===l?void 0:l.inlineSize)&&void 0!==u?u:s.contentRect.width;Math.abs(a-n.current)<1?o():(n.current=a,t())}})});return r.observe(e),r},n={current:null},i={current:null},t={current:null},o=[],r=[n,i,t];return An.current&&o.push(e(An.current,ro,n,function(){return xn.current()},function(){})),En.current&&o.push(e(En.current,lo,i,function(){return xn.current()},function(){return Sn.current()})),cn.current&&o.push(e(cn.current,uo,t,function(){return xn.current()},function(){return Sn.current()})),function(){o.forEach(function(e){return e.disconnect()}),r.forEach(function(e){null!==e.current&&(cancelAnimationFrame(e.current),e.current=null)})}},[]),i.useEffect(function(){Ki.current=Ni},[Ni]),i.useEffect(function(){Yi.current=Vi},[Vi]);var ao=i.useCallback(function(e){var n,i,t,o,r,l="",s="0";if("number"==typeof e)l=(null===(n=vi[e])||void 0===n?void 0:n.nodeId)||(null===(i=vi[e])||void 0===i?void 0:i.id)||"";else{var a=String(e).split(u.DEVIATION_BADGE_SEPARATOR);l=a[0],s=a[1]||"0"}var c=null===(t=null==bn?void 0:bn[l])||void 0===t?void 0:t.evaluation_result,d=Array.isArray(c)?c[parseInt(s,10)]:null==c?void 0:c[s];return!1===(null===(r=null===(o=null==d?void 0:d.evaluation_outputs)||void 0===o?void 0:o.guideline_flag)||void 0===r?void 0:r.rulebook_used)?1:0},[vi,bn]),co=i.useCallback(function(e){var n,i,t=document.querySelectorAll('[id^="guideline-target-"], [data-web-gpt-active="true"]'),o=On.current,r=Tn.current,l="string"==typeof e&&e.includes(u.DEVIATION_BADGE_SEPARATOR),s=e;if(l){var a=e.split(u.DEVIATION_BADGE_SEPARATOR);a.length>=2&&(s="".concat(a[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(a[1]))}var c=(null===(n=Ti.current[s])||void 0===n?void 0:n.current)||(null===(i=Ti.current[e])||void 0===i?void 0:i.current);if(t.length>0&&c&&o&&r){var d=t[0];Bn.current&&(Bn.current.style.height="0px"),wn.current&&(wn.current.style.height="0px"),Dn.current&&(Dn.current.style.height="0px"),In.current&&(In.current.style.height="0px"),requestAnimationFrame(function(){var e=c.getBoundingClientRect(),n=d.getBoundingClientRect(),i=o.getBoundingClientRect(),t=r.getBoundingClientRect(),l=o.scrollTop+(e.top-i.top)+e.height/2,u=r.scrollTop+(n.top-t.top)+n.height/2,s=l-i.height/2,a=Math.max(0,s),f=o.scrollHeight-o.clientHeight,v=a>f?a-f:0,g=i.top+l-a,p=t.top+u-g,h=0;p<0&&(h=Math.abs(p),p=0);var m=r.scrollHeight-r.clientHeight+h,S=p>m?p-m:0;Dn.current&&(Dn.current.style.height="".concat(v,"px")),wn.current&&(wn.current.style.height="".concat(h,"px")),In.current&&(In.current.style.height="".concat(S,"px")),requestAnimationFrame(function(){o.scrollTo({top:a,behavior:"smooth"}),r.scrollTo({top:p,behavior:"smooth"}),Sn.current&&setTimeout(function(){return Sn.current()},50)})})}},[u.DEVIATION_BADGE_SEPARATOR]),fo=i.useCallback(function(){var e,n=Mn.sectionIdx,i=Mn.isOrphan;if(zn(),null!=n){var t="left";Mn.anchorEl&&(null===(e=Tn.current)||void 0===e?void 0:e.contains(Mn.anchorEl))&&(t="right"),st(n),ci&&(sn(ao(n)),Qe(new Set([n]))),Zi(n,i,{sourceSide:t,onReady:function(){ci&&setTimeout(function(){return co(String(n))},150)}})}},[Zi,Mn.isOrphan,Mn.sectionIdx,Mn.anchorEl,zn,st,ci,co,ao]),vo=i.useCallback(function(){zn(),Qi(),Qe(new Set),nn([]),mn.current=[]},[zn,Qi]),go=null!==Mn.sectionIdx&&$e.has(Mn.sectionIdx),po=S.useDeviationNavigation({proposedSections:vi,existingSections:gi,parentDeviationRecord:hi,expandedSections:it,maintainRelativeOrder:!!Me,scrollContainerRef:En,leftContainerRef:On,rightContainerRef:Tn,lhsBadgeRefs:Ti,rhsBadgeRefs:wi}),ho=po.showDeviationNavigation,mo=po.showOpenNodeRef,So=po.adjustScrollForPopup,Ro=i.useCallback(function(e,n,i,t,o){var r,l="string"==typeof t?u.safeStringify(t).trim():u.safeStringify(null==t?void 0:t.deviation_summary).trim(),s=e.currentTarget;Xn();var a="left";(null===(r=Tn.current)||void 0===r?void 0:r.contains(s))&&(a="right");var c=function(){var e,i,t,o;if("string"==typeof n&&n.includes(u.DEVIATION_BADGE_SEPARATOR)){var r=n.split(u.DEVIATION_BADGE_SEPARATOR),l="".concat(r[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(r[1]);return"right"===a?null===(e=wi.current[l])||void 0===e?void 0:e.current:null===(i=Ti.current[l])||void 0===i?void 0:i.current}return"right"===a?null===(t=wi.current[n])||void 0===t?void 0:t.current:null===(o=Ti.current[n])||void 0===o?void 0:o.current};if(i&&!ci)return Qi(),Qe(new Set),nn([]),mn.current=[],void(l&&(st(n),requestAnimationFrame(function(){var e=c()||s;e&&(e.getBoundingClientRect().top>.8*window.innerHeight&&e.scrollIntoView({behavior:"smooth",block:"center"}));Wn({open:!0,anchorEl:e,summary:t,displayImpact:o})})));st(n),ci&&(sn(ao(n)),Qe(new Set([n]))),l?setTimeout(function(){Zi(n,i,{toggleIfSame:!1,sourceSide:a,onReady:function(){var e,i,r,l=c()||s;if(ci)setTimeout(function(){return co(n)},150);else if(l){var u=l.getBoundingClientRect();if(u.top>.8*window.innerHeight||u.top<100){var a=u.top-window.innerHeight/2;Me?(null===(e=On.current)||void 0===e||e.scrollBy({top:a,behavior:"smooth"}),null===(i=Tn.current)||void 0===i||i.scrollBy({top:a,behavior:"smooth"})):null===(r=En.current)||void 0===r||r.scrollBy({top:a,behavior:"smooth"})}}Wn({open:!0,anchorEl:l,summary:t,displayImpact:o})}})},350):setTimeout(function(){Zi(n,i,{toggleIfSame:!1,sourceSide:a}),ci&&setTimeout(function(){return co(n)},150)},350)},[Zi,Xn,Wn,Qi,st,ci,Me,co,bn]),xo=i.useMemo(function(){var e;if(!we)return null;var n=null===(e=null==we?void 0:we.id)||void 0===e?void 0:e.split(":")[0];for(var i in hi){if((hi[i]||[]).some(function(e){return e.id===n}))return i}return null},[we,hi]),_o=i.useRef({id:null,triggerMs:null}),bo=i.useRef(null);i.useEffect(function(){if(null==we?void 0:we.id){var n=Number(we.trigger),i=_o.current;if((null==i?void 0:i.id)!==we.id||(null==i?void 0:i.triggerMs)!==n){if(we.id.includes(":")&&/:\d+$/.test(we.id)){var t=we.id.split(":"),o=t[0],r=t[1],l=null!=r?r:"0",s="".concat(we.id,":").concat(n);bo.current!==s&&(zn(),Xn(),Qi(),Qe(new Set),nn([]),mn.current=[],bo.current=s);var a=!1,c=0,d=null,f=null,v=!1,g=function(e,n){for(var i=function(e,t){if(!e)return null;if(n.includes(e.id)||n.includes(e.nodeId)||n.includes(e.contentId))return t;if(!Array.isArray(e.subsections))return null;for(var o=0;o<e.subsections.length;o++){var r=i(e.subsections[o],"".concat(t,"-").concat(o));if(r)return r}return null},t=0;t<e.length;t++){var o=i(e[t],String(t));if(o)return o}return null},p=function(){var i,t,r;if(!a){var s=function(){_o.current={id:we.id,triggerMs:n}},h=null,m=null;for(var S in hi){var R=hi[S].find(function(e){var n;return e.id===o||e.nodeId===o||e.contentId===o||(null===(n=e.evaluationResult)||void 0===n?void 0:n.nodeId)===o});if(R){h=S,m=R;break}}if(m&&h){var x=Array.from(new Set([o,m.id,m.nodeId,m.contentId,null===(i=m.evaluationResult)||void 0===i?void 0:i.nodeId].filter(Boolean))),_=vi.findIndex(function(e){return e.id===h}),b=gi.findIndex(function(e){return e.id===h}),y=-1===_&&-1!==b,C=g(vi,x),E=g(gi,x);if(C&&!E&&!y){var A=C.split("-"),T=Number(A[0]);if(Me){var w=null===(r=null===(t=vi[T])||void 0===t?void 0:t.refIndexes)||void 0===r?void 0:r[0],I=gi.findIndex(function(e){return e.selfIndex===w});-1!==I&&(T=I)}E=e.__spreadArray([T],A.slice(1),!0).join("-")}if(C||E){var B=C?Number(C.split("-")[0]):_,D=E?Number(E.split("-")[0]):b,O=D>=0?D:E?Number(E.split("-")[0]):-1,F=vi[B],j=gi[O],P=F&&!F.title&&!F.content,k=j&&!j.title&&!j.content,N=y||(!C&&!!E||P&&!k);if(N){if(!(Me?!!Fo.current["right-".concat(D)]:!!Fo.current[String(D)])&&D>=0)return ut(D,"right"),void(d=setTimeout(p,200))}else if(!(Me?!!Fo.current["left-".concat(B)]:!!Fo.current[String(B)])&&B>=0)return ut(B,"left"),void(d=setTimeout(p,200));var M=C||"",L=E||"",q=x.map(function(e){return"".concat(e).concat(u.DEVIATION_BADGE_SEPARATOR).concat(l)}),H=q[0],G=function(){for(var e,n,i=0,t=q;i<t.length;i++){var o=t[i],r=(null===(e=Ti.current[o])||void 0===e?void 0:e.current)||null,l=(null===(n=wi.current[o])||void 0===n?void 0:n.current)||null;if(r||l)return{refId:o,left:r,right:l}}return{refId:H,left:null,right:null}},V=function(e){return"".concat(e).concat(u.DEVIATION_BADGE_SEPARATOR).concat(M).concat(u.DEVIATION_BADGE_SEPARATOR).concat(L)};if(!v){st(V(H)),v=!0,c=0;var W=function(){var e=G(),n=e.left,i=e.right;return N||!n&&!!i?i:n};return null==f||f(),void(d=setTimeout(function(){var e,n,i,t,o,r,l,u;a||(e=W,n=function(){a||(f=null,p())},t=0,o=null,r=null,l=performance.now(),u=function(){if(!a)if(performance.now()-l>3e3)n();else{var s=e();if(s&&0!==s.getBoundingClientRect().height){var c=s.getBoundingClientRect(),d=c.top,f=c.height,v=null!==o&&Math.abs(d-o)<.5,g=null!==r&&Math.abs(f-r)<.5;if(v&&g){if(++t>=5)return void n()}else t=0;o=d,r=f,i=requestAnimationFrame(u)}else i=requestAnimationFrame(u)}},i=requestAnimationFrame(u),f=function(){return cancelAnimationFrame(i)})},300))}var z=G(),K=z.refId,U=z.left,Y=z.right,J=V(K);if(U||Y){var X=N||!U&&!!Y,$=X?Y:U,Q=Me?X?Tn.current:On.current:En.current;if($&&Q){var Z=$.getBoundingClientRect();if(0!==Z.height){var ee=Q.getBoundingClientRect(),ne=Z.top-ee.top+Q.scrollTop-ee.height/2+Z.height/2,ie=(null==C?void 0:C.includes("-"))||(null==E?void 0:E.includes("-")),te=function(){return e.__awaiter(void 0,void 0,void 0,function(){var n,i,t,o,r,c,d,f,v,g;return e.__generator(this,function(p){switch(p.label){case 0:return a?[2]:(s(),n=$ instanceof Element?window.getComputedStyle($).color:"",[U,Y].forEach(function(e){e&&(e.style.transition="box-shadow 300ms ease-in-out",e.style.boxShadow="0 0 10px ".concat(n))}),setTimeout(function(){[U,Y].forEach(function(e){e&&(e.style.boxShadow="")})},2e3),i=(null===(d=null===(c=m.evaluationResult)||void 0===c?void 0:c.deviations)||void 0===d?void 0:d[l])||m,t=(null===(f=m.evaluationResult)||void 0===f?void 0:f.evaluation_outputs)||m.evaluation_outputs,!!U&&!!Y||ci?(r=function(e,n){return Promise.race([e,new Promise(function(e){return setTimeout(e,n)})])},Me?[4,Promise.all([On.current?r(u.waitForScrollIdle(On.current),600):Promise.resolve(),Tn.current?r(u.waitForScrollIdle(Tn.current),600):Promise.resolve()])]:[3,2]):(o=X?(null===(v=wi.current[ie?K:D])||void 0===v?void 0:v.current)||Y:(null===(g=Ti.current[ie?K:B])||void 0===g?void 0:g.current)||U,So(o,function(){Wn({open:!0,anchorEl:o,displayImpact:we.displayImpact,summary:e.__assign(e.__assign({},i),{evaluation_outputs:t})})},{skipScroll:!0}),null==Ie||Ie(),[2]));case 1:p.sent(),p.label=2;case 2:return ci&&(sn(ao(J)),Qe(new Set([J]))),et.current(J,!1,{toggleIfSame:!1,sourceSide:y?"right":"left",onReady:function(){var n,t,o,r;s();var l=X?(null===(n=wi.current[K])||void 0===n?void 0:n.current)||Y:(null===(t=Ti.current[K])||void 0===t?void 0:t.current)||U;if(ci)setTimeout(function(){return co(J)},150);else{var u=(null===(o=Ti.current[K])||void 0===o?void 0:o.current)||U,a=(null===(r=wi.current[K])||void 0===r?void 0:r.current)||Y;u&&(u.style.scrollMarginTop="150px",u.scrollIntoView({behavior:"smooth",block:"start"})),a&&(a.style.scrollMarginTop="150px",a.scrollIntoView({behavior:"smooth",block:"start"}))}Wn({open:!0,anchorEl:l,displayImpact:we.displayImpact,summary:e.__assign({},i)}),null==Ie||Ie()}}),[2]}})})};Math.abs(Q.scrollTop-ne)<=2?te():u.scrollAndWait(Q,ne,te)}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}};return d=setTimeout(p,100),function(){a=!0,d&&clearTimeout(d),null==f||f()}}_o.current={id:we.id,triggerMs:n},Ht(we.id);var h=vi.findIndex(function(e){return e.id===we.id}),m=gi.findIndex(function(e){return e.id===we.id});-1===h&&-1===m||setTimeout(function(){var e=-1!==h?h:m,n=-1===h;ci&&sn(ao(e)),Qe(new Set([e])),et.current(e,n,{sourceSide:n?"right":"left",onReady:function(){ci&&setTimeout(function(){return co(String(e))},150)}})},400)}}},[null==we?void 0:we.id,null==we?void 0:we.trigger,null==we?void 0:we.displayImpact,hi,vi,gi,Me,Wn,Ht,ci,ao,co]),i.useEffect(function(){var n,i,t;if(Vn.open){var o=Vn.anchorEl;if(o&&!o.isConnected){var r=function(e){for(var n,i=0,t=Object.entries(e);i<t.length;i++){var r=t[i],l=r[0];if((null===(n=r[1].current)||void 0===n?void 0:n.textContent)===o.textContent)return l}return null},l=(null===(n=o.dataset)||void 0===n?void 0:n.deviationRefId)||r(Ti.current)||r(wi.current);if(l){var u=(null===(i=wi.current[l])||void 0===i?void 0:i.current)||(null===(t=Ti.current[l])||void 0===t?void 0:t.current);u&&u.isConnected&&Wn(function(n){return e.__assign(e.__assign({},n),{anchorEl:u})})}}}},[Vn.open,Vn.anchorEl,on,$e,it]);var yo=kn.open,Co=kn.sectionIdx,Eo=kn.isOrphan,Ao=kn.badgeStyle,To=kn.anchorEl,wo=kn.sectionAnchorEl;i.useEffect(function(){var n;if(ye.isStreamingEnabled&&yo&&null!=Co&&Co!==pt){var i="string"==typeof Co?Co.split(u.DEVIATION_BADGE_SEPARATOR)[0]:null,t=function(e,n){var i;if(!e||!Array.isArray(e))return null;for(var o=0,r=e;o<r.length;o++){var l=r[o];if(l.id===n)return l;if(null===(i=l.subsections)||void 0===i?void 0:i.length){var u=t(l.subsections,n);if(u)return u}}return null},o=i&&"string"==typeof i?t(vi,i):null,r=i&&"string"==typeof i?t(gi,i):null,l="number"==typeof Co?vi[Co]||null:o||i&&((null===(n=null==he?void 0:he.nodes)||void 0===n?void 0:n[i])||(null==he?void 0:he[i]))||null,s="number"==typeof Co?gi[Co]||null:r,a=Nt(To,l,s,Co,Eo,Ao);Nn(function(n){return n.open?u.safeStringify(n.cognitiveData)===u.safeStringify(a.cognitiveData)&&u.safeStringify(n.deviationData)===u.safeStringify(a.deviationData)&&n.sectionTitle===a.sectionTitle&&n.refSectionTitle===a.refSectionTitle?n:e.__assign(e.__assign(e.__assign({},n),a),{open:!0,anchorEl:n.anchorEl,sectionAnchorEl:n.sectionAnchorEl}):n})}},[yo,Co,Eo,Ao,To,wo,vi,gi,Nt]);var Io=i.useCallback(function(e){var i=e.section,t=e.keyPath,o=e.depth,r=void 0===o?0:o,l=e.columnKey,u=void 0===l?"left":l,s=e.parentNodeId,a=void 0===s?"":s,c=e.sectionOffset,d=e.rhsOrphanVisualIndexes;return n.jsx(x.default,{section:i,keyPath:t,depth:r,columnKey:u,parentNodeId:a,sectionOffset:c,rhsOrphanVisualIndexes:d})},[]),Bo=i.useMemo(function(){return vi.map(function(e,i){var t,o,r=!(null==e?void 0:e.title)&&!(null==e?void 0:e.content),l=!(null==e?void 0:e.refIndexes)||0===e.refIndexes.length;return r&&l&&Me?null:n.jsx(_.default,{section:e,idx:i},null!==(o=null!==(t=null==e?void 0:e.layoutKey)&&void 0!==t?t:null==e?void 0:e.id)&&void 0!==o?o:"left-row-".concat(i))})},[vi,Me]),Do=i.useMemo(function(){return gi.map(function(e,i){var t,o,r=!(null==e?void 0:e.title)&&!(null==e?void 0:e.content),l=!(null==e?void 0:e.refIndexes)||0===e.refIndexes.length;return r&&l&&Me?null:n.jsx(b.default,{section:e,idx:i},null!==(o=null!==(t=null==e?void 0:e.layoutKey)&&void 0!==t?t:null==e?void 0:e.id)&&void 0!==o?o:"right-row-".concat(i))})},[gi,Me]),Oo=i.useRef(Mt);i.useEffect(function(){Oo.current=Mt},[Mt]);var Fo=i.useRef(it);i.useEffect(function(){Fo.current=it},[it]);var jo=i.useRef(Ro);i.useEffect(function(){jo.current=Ro},[Ro]);var Po=i.useRef(vo);i.useEffect(function(){Po.current=vo},[vo]);var ko=i.useRef(ut);i.useEffect(function(){ko.current=ut},[ut]);var No=i.useRef(lt);i.useEffect(function(){No.current=lt},[lt]);var Mo=i.useRef(Io);i.useEffect(function(){Mo.current=Io},[Io]);var Lo=i.useRef(Qi);i.useEffect(function(){Lo.current=Qi},[Qi]);var qo=i.useMemo(function(){return{isGuidelineMode:ci,maintainRelativeOrder:!!Me,showDeviationBadges:Ge,isProposingFix:De,proposingFixNodeId:Oe,isRedlineFlow:Fe,isSideBySide:Ni,activeSideBySideSection:Vi,scrollSyncLocked:on,toggleScrollSyncLocked:ct,summaryPopupAnchorEl:Vn.anchorEl,connectedSections:$e,proposedSections:vi,existingSections:gi,deviationNumberRegistry:mi,deviationParentRegistry:Si,treeData:he,displayConfig:ye,resolvedMarkdownStyles:Cn,unifiedNumbering:dt,expandedSections:it,expandedSubSections:ot,setExpandedSubSections:rt,getSectionCompareStyle:Kt,getSubSectionCompareStyle:Ut,getBadgeRef:Pi,getSectionRowRef:Fi,getSubSectionRef:ji,sectionLeftRefs:Ei,sectionRightRefs:Ai,sectionRowRefs:Oi,sectionRightRowRefs:Ii,subSectionLeftRefs:Bi,subSectionRightRefs:Di,lhsBadgeRefs:Ti,rhsBadgeRefs:wi,openMoreFunctionsPopup:bt,handleOpenSummaryPopup:yt,openSummaryPopup:yt,handleCloseSummaryPopup:Ct,toggleSection:Et,handleSubSectionToggle:At,renderSubSectionAccordion:Tt,resetSideBySide:wt,setConnectedSections:Qe,setConnectedLines:nn,cachedConnectedPositions:mn,showDeviationNavigation:ho,showOpenNodeRef:mo,deviationNodeIdToView:null==we?void 0:we.id,deviationTargetParentId:xo,guidelinesData:Pe,gptWebCitationConfig:ke}},[ci,Me,Ge,De,Oe,Fe,Ni,Vi,on,ct,Vn.anchorEl,$e,vi,gi,mi,ye,Cn,dt,it,ot,rt,Kt,Ut,Pi,Fi,ji,ho,mo,we,xo,Pe,ke]),Ho=u.safeStringify(kn.sectionTitle||ri||ti),Go=u.safeStringify(ci?ui||si||kn.refSectionTitle:kn.refSectionTitle||ui||si);return n.jsx(C.CompareContextProvider,e.__assign({value:qo},{children:n.jsxs(t.Box,e.__assign({ref:An,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[We&&n.jsx(t.Box,e.__assign({sx:{position:"absolute",inset:0,bgcolor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(10px)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"8px"}},{children:n.jsx(f.default,{})})),Vn.open&&n.jsx(y.default,{open:Vn.open,anchorEl:Vn.anchorEl,containerEl:Vt.current,clipTopEl:dn.current,scrollContainerEl:En.current,onClose:vo,summary:Vn.summary,displayImpact:Vn.displayImpact,isScrollLocked:on}),n.jsx(d.default,{open:Mn.open,anchorEl:Mn.anchorEl,maintainRelativeOrder:!!Me,sectionTitle:Mn.sectionTitle,referenceSectionTitle:Mn.refSectionTitle,onClose:$n,onOpenCognitiveCompare:Yn,onOpenSideBySide:fo,onConnect:Lt,isConnected:go,isOrphan:!ci&&!!Mn.isOrphan,isGuidelineMode:ci,hasGuidelineMatches:Mn.hasGuidelineMatches}),kn.open&&n.jsx(c.default,{open:kn.open,popupRef:Un,position:qn,popupConfig:Ee,onClose:function(){Hn(null),Nn(function(n){return e.__assign(e.__assign({},n),{open:!1})}),Kn(null)},markdownStyles:xe,sectionTitle:Ho,referenceSectionTitle:Go,cognitiveData:kn.cognitiveData,anchorEl:kn.anchorEl,sectionAnchorEl:kn.sectionAnchorEl,scrollContainerEl:En.current,badgeStyle:kn.badgeStyle,docData:kn.docData,deviationData:kn.deviationData,isLoading:kn.isLoading}),n.jsx(t.Snackbar,e.__assign({open:!!Ue,autoHideDuration:8e3,onClose:function(){return Ye(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(t.Alert,e.__assign({onClose:function(){return Ye(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:Ue}))})),n.jsx(R.default,{componentHeaderText:pe,displayConfig:ye,maintainRelativeOrder:Me,onCollapseAll:io,showCollapseAll:to,onToggleView:function(e){ze(!0),setTimeout(function(){Le(!e),null==Ce||Ce(!e),rn(!1),Qi(),zn(),Qe(new Set),nn([]),mn.current=[],requestAnimationFrame(function(){requestAnimationFrame(function(){setTimeout(function(){ze(!1)},600)})})},50)}}),n.jsx(t.Box,e.__assign({ref:En,onScroll:no,sx:{flex:1,minHeight:0,pt:1.5,pb:1,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",overflowY:Me?"visible":"auto",borderTop:vt&&gt?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(t.Box,e.__assign({sx:e.__assign({display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"},Me?{flex:1}:{})},{children:n.jsxs(t.Box,e.__assign({ref:cn,sx:e.__assign({display:"grid",gridTemplateColumns:"minmax(0, 1fr) 180px minmax(0, 1fr)",gap:"100px",maxWidth:"1200px",width:"100%",position:"relative",minHeight:0},Me?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(I.default,{svgContainerRef:an,svgDimensions:eo,isResizing:qi,overallConnector:Qt,rootDeviationStyle:St,lines:Xt,isSideBySide:Ni,activeSideBySideSection:Vi,isArrowVisible:Mi,maintainRelativeOrder:Me,proposedSections:vi,existingSections:gi,cognitivePopup:kn,activeBadgeId:Gn,closeCognitivePopup:Xn,setActiveBadgeId:Kn,openCognitivePopupFromState:Jn,buildSectionPopupState:Nt,connectedLines:en,isGuidelineMode:ci,pathRefs:hn}),n.jsxs(t.Box,e.__assign({sx:e.__assign({border:"1px solid #E7E7E9",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)"},Me?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(t.Box,e.__assign({ref:dn,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E7E7E9",borderRadius:"8px 8px 0 0",display:"flex",alignItems:"center",minHeight:"40px",overflow:"hidden",minWidth:0}},{children:n.jsx(t.Tooltip,e.__assign({title:ti,placement:"top"},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,textAlign:"center",display:"block"}},{children:ti}))}))})),n.jsxs(t.Box,e.__assign({ref:On,onScroll:no,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},Me?{maxHeight:"calc(100vh - 250px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,mr:"-180px",pr:"192px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:Bn,style:{width:"100%",height:"0px",flexShrink:0}}),xi&&Bo,n.jsx("div",{ref:Dn,style:{width:"100%",height:"0px",flexShrink:0}})]}))]})),n.jsx(t.Box,e.__assign({ref:Vt,sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"15px",gap:0,zIndex:20,pointerEvents:"none"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(t.Box,e.__assign({onClick:function(n){n.stopPropagation(),kn.open&&Gn===pt?Xn():(Kn(pt),Jn(Nt(n.currentTarget,{title:Ft,content:"",evaluationResult:ht,cognitiveData:{section_id:"",decisioning:[],gap:[],relevance_score:0,isMissingRationale:!0}},null,pt,!0,e.__assign(e.__assign({},St),{label:""}))))},sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:"5px",top:"-8px",borderRadius:"20px",bgcolor:St.badgeBg,color:St.badgeText,border:"1px solid ".concat(St.badgeBorder),fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",position:"relative",zIndex:1,pointerEvents:"auto",cursor:"pointer"}},{children:[null!=mt?mt:n.jsx(v.default,{}),n.jsx(t.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(r.ButtonCognitiveIcon,{})})),n.jsx(o.ChevronDown,{size:11,style:{transform:kn.open&&Gn===pt?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.25s ease"}})]}))}))})),n.jsxs(t.Box,e.__assign({sx:e.__assign({border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0},Me?{flex:1,overflow:"visible",minHeight:0}:{})},{children:[Gi&&n.jsx(l.default,{sections:11}),n.jsx(t.Box,e.__assign({ref:fn,sx:e.__assign({p:"8px",bgcolor:ci?"#F1F3F5":"#F7F8FA",borderBottom:"1px solid #D7DCE2",borderRadius:"8px 8px 0 0",display:"flex",alignItems:"center"},Me?e.__assign({maxHeight:"calc(100vh - 250px)",overflowY:"auto",overflowX:"hidden",minHeight:0},ci?{"&::-webkit-scrollbar":{width:"6px",display:"block"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"#CBD5E1",borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:"#94A3B8"},scrollbarWidth:"thin",scrollbarColor:"#CBD5E1 transparent"}:{"&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}):{})},{children:ci?n.jsxs(t.Tabs,e.__assign({value:un,onChange:function(e,n){return sn(n)},variant:"fullWidth",TabIndicatorProps:{sx:{display:"none"}},sx:{width:"100%",minHeight:"36px","& .MuiTab-root":{minHeight:"36px",px:1,py:0,borderRadius:"8px",fontSize:"14px",lineHeight:1,fontWeight:500,textTransform:"none",color:"#374151",minWidth:0,transition:"background-color 160ms ease, box-shadow 160ms ease"},"& .Mui-selected":{color:"#374151",bgcolor:"#FFFFFF"}}},{children:[n.jsx(t.Tab,{label:n.jsx(t.Tooltip,e.__assign({title:si,placement:"top"},{children:n.jsx(t.Box,e.__assign({component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",width:"100%"}},{children:"Redline Guidelines"}))}))}),n.jsx(t.Tab,{label:n.jsx(t.Tooltip,e.__assign({title:"Web & GPT Sources",placement:"top"},{children:n.jsx(t.Box,e.__assign({component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",width:"100%"}},{children:"Web & GPT Sources"}))}))})]})):n.jsx(t.Tooltip,e.__assign({title:si,placement:"top"},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,textAlign:"center",display:"block"}},{children:si}))}))})),n.jsxs(t.Box,e.__assign({ref:Tn,onScroll:no,sx:e.__assign({p:ci?"0px":"12px",display:"flex",flexDirection:"column"},Me?e.__assign(e.__assign({maxHeight:"calc(100vh - 250px)"},!ci&&{flex:1}),{overflowY:"auto",overflowX:"hidden",minHeight:0,ml:"-150px",pl:"165px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}):{})},{children:[n.jsx("div",{ref:wn,style:{width:"100%",height:"0px",flexShrink:0}}),ci?0===un?n.jsx(B.default,{guidelinesData:Pe,deviationData:Te,connectedSections:$e,proposedSections:vi}):n.jsx(D.default,{deviationData:Te,connectedSections:$e,proposedSections:vi}):xi&&Do,n.jsx("div",{ref:In,style:{width:"100%",height:"0px",flexShrink:0}})]}))]}))]}))}))}))]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),i=require("react"),t=require("@mui/material"),o=require("lucide-react"),r=require("../../assests/svg/ButtonCognitiveIcon.js"),l=require("./OverlayComponent.js"),u=require("./CognitiveComparehelpers.js"),s=require("./CognitiveCompareConfig.js"),a=require("./CognitiveCompareConstants.js"),c=require("./CognitivePopup.js"),d=require("./MoreFunctionsPopup.js"),f=require("./LoaderComponent.js"),v=require("./components/ThreeDotsLoader.js"),g=require("./hooks/useCompareData.js"),p=require("./hooks/useComparePopups.js"),h=require("./hooks/useSectionRefs.js"),m=require("./hooks/useAccordionState.js"),S=require("./hooks/useDeviationNavigation.js"),R=require("./components/CompareHeader.js"),x=require("./components/SubSectionAccordion.js"),_=require("./components/LHSSectionRow.js"),b=require("./components/RHSSectionRow.js"),y=require("./components/CognitiveSummaryPopup.js"),C=require("./CompareContext.js"),E=require("./hooks/useStyles.js"),A=require("./hooks/useResizeHandler.js"),T=require("./hooks/useLinesCalculator.js"),I=require("./hooks/useSideBySide.js"),w=require("./components/SvgConnectors.js"),B=require("./Guidelines/components/GuidelinePanel.js"),D=require("./Guidelines/components/WebGptPanel.js"),O=require("./Guidelines/utils/guidelineTargets.js");exports.SHARED_MARKDOWN_STYLES=s.SHARED_MARKDOWN_STYLES,exports.default=function(F){var j,P,k,N,M,L,q,G,H,V,W,z,K,U,Y,J,X,$,Q,Z,ee,ne,ie,te,oe,re,le,ue,se,ae,ce,de,fe,ve,ge,pe=F.componentHeaderText,he=void 0===pe?a.DEFAULT_COMPONENT_HEADER_TEXT:pe,me=F.treeData,Se=F.comparisonConfig,Re=F.leftColumnTitleText,xe=F.rightColumnTitleText,_e=F.markdownStyles,be=F.resetTrigger,ye=F.displayConfig,Ce=void 0===ye?{isHeaderVisible:!0,isToggleVisible:!0,maintainRelativeOrder:!1,isLoading:!0,showDeviationBadges:!1,enableDeviationSchemaBackwardCompatibility:!1,displayEmailNotifier:!0,isStreamingEnabled:!1}:ye,Ee=F.onMaintainRelativeOrderChange,Ae=F.popupConfig,Te=F.deviationData,Ie=void 0===Te?{}:Te,we=F.deviationNodeIdToView,Be=F.resetDeviationNodeId,De=F.isProposingFix,Oe=void 0!==De&&De,Fe=F.proposingFixNodeId,je=F.isRedlineFlow,Pe=F.badgeStyleOverride,ke=F.guidelinesData,Ne=F.isGuidelineMode,Me=F.gptWebCitationConfig,Le=i.useState(Ce.maintainRelativeOrder),qe=Le[0],Ge=Le[1],He=null!==(j=null==Ce?void 0:Ce.expandLevels)&&void 0!==j?j:0,Ve=!!(null==Ce?void 0:Ce.expandAllSections),We=!!qe||!!(null==Ce?void 0:Ce.showDeviationBadges),ze=i.useState(!1),Ke=ze[0],Ue=ze[1],Ye=i.useState(null),Je=Ye[0],Xe=Ye[1],$e=i.useState(null===(k=null!==(P=null==me?void 0:me.newEvaluationResult)&&void 0!==P?P:null==Ce?void 0:Ce.enableDeviationSchemaBackwardCompatibility)||void 0===k||k)[0],Qe=i.useState(new Set),Ze=Qe[0],en=Qe[1],nn=i.useState([]),tn=nn[0],on=nn[1],rn=i.useState(!1),ln=rn[0],un=rn[1],sn=i.useState(0),an=sn[0],cn=sn[1],dn=i.useRef(null),fn=i.useRef(null),vn=i.useRef(null),gn=i.useRef(null),pn=i.useRef(null),hn=i.useRef(!1),mn=i.useRef(null),Sn=i.useRef({}),Rn=i.useRef([]),xn=i.useRef(function(){}),_n=i.useRef(null),bn=i.useRef(function(){}),yn=i.useMemo(function(){return JSON.stringify(Ie||{})},[JSON.stringify(Ie)]),Cn=i.useMemo(function(){return Ie||{}},[yn]),En=i.useMemo(function(){return(null==me?void 0:me.cognitive_decisioning)||{}},[me]),An=i.useMemo(function(){return e.__assign(e.__assign({},s.SHARED_MARKDOWN_STYLES),_e)},[_e]),Tn=i.useRef(null),In=i.useRef(null),wn=i.useRef(null),Bn=i.useRef(null),Dn=i.useRef(null),On=i.useRef(null),Fn=i.useRef(null),jn=i.useRef(null),Pn=i.useRef(null),kn=i.useRef(null),Nn=p.useComparePopups(Tn),Mn=Nn.cognitivePopup,Ln=Nn.setCognitivePopup,qn=Nn.moreFunctions,Gn=Nn.setMoreFunctions,Hn=Nn.position,Vn=Nn.setPosition,Wn=Nn.activeBadgeId,zn=Nn.summaryPopup,Kn=Nn.setSummaryPopup,Un=Nn.closeSummaryPopup,Yn=Nn.setActiveBadgeId,Jn=Nn.popupRef,Xn=Nn.handleOpenCognitiveCompare,$n=Nn.openCognitivePopupFromState,Qn=Nn.closeCognitivePopup,Zn=Nn.closeMoreFunctionsPopup,ei=i.useMemo(function(){var e,n,i,t,o,r,l;return{fields:null!==(e=null==Se?void 0:Se.fields)&&void 0!==e?e:s.DEFAULT_FIELD_CONFIG,thresholds:{high:null!==(i=null===(n=null==Se?void 0:Se.thresholds)||void 0===n?void 0:n.high)&&void 0!==i?i:s.DEFAULT_COMPARISON_CONFIG.thresholds.high,medium:null!==(o=null===(t=null==Se?void 0:Se.thresholds)||void 0===t?void 0:t.medium)&&void 0!==o?o:s.DEFAULT_COMPARISON_CONFIG.thresholds.medium,exact:null!==(l=null===(r=null==Se?void 0:Se.thresholds)||void 0===r?void 0:r.exact)&&void 0!==l?l:s.DEFAULT_COMPARISON_CONFIG.thresholds.exact}}},[Se]),ni=i.useState(null),ii=ni[0];ni[1];var ti=null===(L=null===(N=null==me?void 0:me.documents)||void 0===N?void 0:N[null===(M=null==me?void 0:me.input_index_map)||void 0===M?void 0:M[0]])||void 0===L?void 0:L.title,oi=null===(H=null===(q=null==me?void 0:me.documents)||void 0===q?void 0:q[null===(G=null==me?void 0:me.input_index_map)||void 0===G?void 0:G[1]])||void 0===H?void 0:H.title,ri=u.safeStringify(Re||ti||"Uploaded Contract"),li=null===(K=null===(z=null===(V=null==me?void 0:me.documents)||void 0===V?void 0:V[null===(W=null==me?void 0:me.input_index_map)||void 0===W?void 0:W[0]])||void 0===z?void 0:z.metadata)||void 0===K?void 0:K.file_name,ui=u.safeStringify(li),si=null===(X=null===(J=null===(U=null==me?void 0:me.documents)||void 0===U?void 0:U[null===(Y=null==me?void 0:me.input_index_map)||void 0===Y?void 0:Y[1]])||void 0===J?void 0:J.metadata)||void 0===X?void 0:X.file_name,ai=u.safeStringify(si),ci=u.safeStringify(xe||oi||"Reference Template"),di=g.useCognitiveTreeData(me,qe,Cn,ei,$e,ke,Ne),fi=di.isGuidelineMode,vi=di.activeProposed,gi=di.existingRule,pi=di.proposedSections,hi=di.existingSections,mi=di.visibleFields,Si=di.parentDeviationRecord,Ri=di.deviationNumberRegistry,xi=di.deviationParentRegistry,_i=di.parseError;i.useEffect(function(){_i&&Xe("Failed to load comparison: ".concat(_i))},[_i]);var bi=pi.length>0||hi.length>0,yi=i.useMemo(function(){if(!je)return"off";var e=0,n=0,i=function(t){Array.isArray(t)&&t.forEach(function(t){var o,r=(null==t?void 0:t.content)||"";u.hasMeaningfulRedlineTags(r)&&(e+=1,n+=String(r).length),(null===(o=null==t?void 0:t.subsections)||void 0===o?void 0:o.length)&&i(t.subsections)})};return i(pi),i(hi),"".concat(e,":").concat(n)},[je,pi,hi]);i.useEffect(function(){if(pi.length||hi.length)if(Ve){var e={},n={},i=function(i,t){i.forEach(function(i,o){var r,l=qe?"".concat(t,"-").concat(o):String(o);e[l]=!0;var u=function(e,i){null==e||e.forEach(function(e,t){var o,r="".concat(i,"-").concat(t);n[r]=!0,(null===(o=e.subsections)||void 0===o?void 0:o.length)&&u(e.subsections,r)})};(null===(r=i.subsections)||void 0===r?void 0:r.length)&&u(i.subsections,String(o))})};i(pi,"left"),i(hi,"right"),rt(e),ut(n)}else if(He>0){var t={},o={},r=function(e,n,i){e.forEach(function(e,r){var l;if(i>=1){var u=qe?"".concat(n,"-").concat(r):String(r);t[u]=!0}var s=function(e,n,t){t>i||null==e||e.forEach(function(e,i){var r,l="".concat(n,"-").concat(i);o[l]=!0,(null===(r=e.subsections)||void 0===r?void 0:r.length)&&s(e.subsections,l,t+1)})};(null===(l=e.subsections)||void 0===l?void 0:l.length)&&i>=2&&s(e.subsections,String(r),2)})};r(pi,"left",He),r(hi,"right",He),rt(t),ut(o)}},[Ve,He,pi,hi,qe]);var Ci=h.useSectionRefs(mi.map(function(e){return e.key}),Math.max(pi.length,hi.length)),Ei=Ci.leftRefs,Ai=Ci.rightRefs,Ti=Ci.sectionLeftRefs,Ii=Ci.sectionRightRefs,wi=Ci.lhsBadgeRefs,Bi=Ci.rhsBadgeRefs,Di=Ci.sectionRightRowRefs,Oi=Ci.subSectionLeftRefs,Fi=Ci.subSectionRightRefs,ji=Ci.sectionRowRefs,Pi=Ci.getSectionRowRef,ki=Ci.getSubSectionRef,Ni=Ci.getBadgeRef,Mi=I.useSideBySide({isGuidelineMode:fi,maintainRelativeOrder:qe,proposedSections:pi,existingSections:hi,leftContainerRef:jn,rightContainerRef:wn,scrollContainerRef:Tn,sectionLeftRefs:Ti,sectionRightRefs:Ii,subSectionLeftRefs:Oi,subSectionRightRefs:Fi,lhsBadgeRefs:wi,rhsBadgeRefs:Bi,sectionRowRefs:ji,sectionRightRowRefs:Di,rhsTopSpacerRef:Bn,rhsBottomSpacerRef:Dn,lhsTopSpacerRef:On,lhsBottomSpacerRef:Fn,calculateLinesRef:xn,setConnectedSections:en,setConnectedLines:on,cachedConnectedPositions:Rn,closeMoreFunctionsPopup:Zn,setErrorToast:Xe,moreFunctions:qn,closeSummaryPopup:Un}),Li=Mi.isSideBySide,qi=Mi.isArrowVisible,Gi=Mi.setIsArrowVisible,Hi=Mi.isResizing,Vi=Mi.setIsResizing,Wi=Mi.isSideBySideLoading,zi=Mi.activeSideBySideSection,Ki=Mi.scrollLock,Ui=Mi.sideBySideCacheRef,Yi=Mi.isSideBySideRef,Ji=Mi.activeSideBySideRightSectionRef,Xi=Mi.activeSideBySideSectionRef,$i=Mi.sideBySideLineRef,Qi=Mi.highlightedClauseRefs,Zi=Mi.clearClauseHighlight,et=Mi.resetSideBySide,nt=Mi.activateSideBySide,it=i.useRef(nt);i.useEffect(function(){it.current=nt},[nt]);var tt=m.useAccordionState({maintainRelativeOrder:!!qe,proposedSections:pi,existingSections:hi,activeSideBySideSection:zi,connectedSections:Ze,resetSideBySide:et,setConnectedSections:en,setConnectedLines:on,cachedConnectedPositions:Rn,svgContainerRef:dn,isAnimatingRef:hn,animationTimerRef:mn,calculateLinesRef:xn,sectionLeftRefs:Ti,sectionRightRefs:Ii,subSectionLeftRefs:Oi,subSectionRightRefs:Fi}),ot=tt.expandedSections,rt=tt.setExpandedSections,lt=tt.expandedSubSections,ut=tt.setExpandedSubSections,st=tt.handleSubSectionToggle,at=tt.toggleSection,ct=tt.forceExpandCrossWiredSections,dt=function(){var e,n;if(null!=zi){var i=null===(e=Ti.current[zi])||void 0===e?void 0:e.current,t=null===(n=Ii.current[zi])||void 0===n?void 0:n.current,o=wn.current;if(i&&t&&o){var r=i.getBoundingClientRect(),l=t.getBoundingClientRect(),u=o.getBoundingClientRect(),s=r.top-u.top,a=l.top-u.top-s;o.scrollBy({top:a,behavior:"smooth"})}}},ft=i.useCallback(function(e){null==e||e.stopPropagation(),un(function(e){var n=!e;return n&&requestAnimationFrame(function(){dt()}),n})},[dt]);i.useEffect(function(){je&&"off"!==yi&&"0:0"!==yi&&(Ui.current=null,Rn.current=[],requestAnimationFrame(function(){var e;null===(e=xn.current)||void 0===e||e.call(xn)}))},[je,yi]);var vt=i.useMemo(function(){var e=new Map,n=new Map,i=1;if(qe)pi.forEach(function(n){!n.title&&!n.content||n.id&&e.set(n.id,i++)}),hi.forEach(function(t){if(t.id&&!(!t.title&&!t.content)){var o=pi.filter(function(e){var n;return null===(n=e.refIndexes)||void 0===n?void 0:n.includes(t.selfIndex)});if(o.length>0){var r=o.map(function(n){return e.get(n.id)}).filter(Boolean);n.set(t.id,r.join(", "))}else n.set(t.id,String(i++))}});else for(var t=Math.max(pi.length,hi.length),o=0;o<t;o++){var r=pi[o],l=hi[o];r?(e.set(r.id,i),l&&n.set(l.id,String(i)),i++):l&&n.set(l.id,String(i++))}return{leftNums:e,rightNums:n}},[pi,hi,qe]),gt=gi.analysis,pt=u.safeStringify(null===(Q=null===($=null==gt?void 0:gt.rule_difference_comparison)||void 0===$?void 0:$.summary)||void 0===Q?void 0:Q.overall_summary),ht=!!pt.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),mt=null!==(Z=null==me?void 0:me.base_root_id)&&void 0!==Z?Z:"-1";null==me||me[mt];var St=$e?null!==(de=null!==(se=Ie&&(null===(ue=null==Ie?void 0:Ie[mt])||void 0===ue?void 0:ue.evaluation_result))&&void 0!==se?se:null===(ce=null===(ae=null==me?void 0:me.nodes)||void 0===ae?void 0:ae[mt])||void 0===ce?void 0:ce.evaluation_result)&&void 0!==de?de:null:null!==(le=null!==(ie=Ie&&(null===(ne=null===(ee=null==Ie?void 0:Ie[mt])||void 0===ee?void 0:ee.evaluation_result)||void 0===ne?void 0:ne[0]))&&void 0!==ie?ie:null===(re=null===(oe=null===(te=null==me?void 0:me.nodes)||void 0===te?void 0:te[mt])||void 0===oe?void 0:oe.evaluation_result)||void 0===re?void 0:re[0])&&void 0!==le?le:null,Rt=u.extractDeviationScore(St),xt=u.generateColorPalette(null!==(ge=null===(ve=null===(fe=null==St?void 0:St.evaluation_outputs)||void 0===fe?void 0:fe.metadata)||void 0===ve?void 0:ve.label_color)&&void 0!==ge?ge:a.DEFAULT_DEVIAION_COLOR);if(Pe){var _t=Pe(Rt);_t&&(xt=e.__assign(e.__assign({},xt),{badgeBg:_t.bg,badgeText:_t.text,badgeBorder:_t.border}))}var bt=i.useRef(et);i.useEffect(function(){bt.current=et},[et]);var yt=i.useRef(Qn);i.useEffect(function(){yt.current=Qn},[Qn]);var Ct=i.useCallback(function(e,n,i,t,o,r){return jo.current(e,n,i,t,o,r)},[]),Et=i.useCallback(function(e,n,i,t,o){return ko.current(e,n,i,t,o)},[]),At=i.useCallback(function(){return No.current()},[]),Tt=i.useCallback(function(e,n){return Mo.current(e,n)},[]),It=i.useCallback(function(e){return Lo.current(e)},[]),wt=i.useCallback(function(e){return qo.current(e)},[]),Bt=i.useCallback(function(){return Go.current()},[]),Dt=i.useCallback(function(){var e,n;Zi(),null===(e=bt.current)||void 0===e||e.call(bt),un(!1),en(new Set),on([]),Rn.current=[],Zt([]),no(null),Kn(a.EMPTY_SUMMARY_POPUP_STATE),null===(n=yt.current)||void 0===n||n.call(yt),requestAnimationFrame(function(){var e;null===(e=xn.current)||void 0===e||e.call(xn)})},[]),Ot=i.useRef(Dt);i.useEffect(function(){Ot.current=Dt},[Dt]),i.useEffect(function(){be&&Ot.current()},[be]);var Ft=i.useMemo(function(){return{documents:null==me?void 0:me.documents,input_index_map:null==me?void 0:me.input_index_map}},[JSON.stringify(null==me?void 0:me.documents),JSON.stringify(null==me?void 0:me.input_index_map)]),jt=i.useState(""),Pt=jt[0],kt=jt[1],Nt=i.useRef(me);i.useEffect(function(){var e,n,i;Nt.current=me;var t=null===(e=null==me?void 0:me.input_index_map)||void 0===e?void 0:e[0],o=null===(i=null===(n=null==me?void 0:me.documents)||void 0===n?void 0:n[t])||void 0===i?void 0:i.title;kt(o)},[me]);var Mt=i.useRef(En);i.useEffect(function(){Mt.current=En},[En]);var Lt=i.useCallback(function(n,i,t,o,r,l,s){var a,c,d,f,v,g,p,h,m,S,R=u.safeStringify(null==i?void 0:i.id)||u.safeStringify(null==t?void 0:t.id)||"",x=(R?null===(a=Mt.current)||void 0===a?void 0:a[R]:null)||(null==i?void 0:i.cognitiveData)||(null==t?void 0:t.cognitiveData)||{section_id:R,decisioning:[],gap:[],relevance_score:0},_=null!==(d=null===(c=ji.current[o])||void 0===c?void 0:c.current)&&void 0!==d?d:null,b=function(){var n,r,l=(null==i?void 0:i.evaluationResult)||(null==t?void 0:t.evaluationResult)||null,s=function(n){var i=function(e){if(!e||"object"!=typeof e)return null;var n=null==e?void 0:e.deviation_entries;if(n&&"object"==typeof n){var i=Object.keys(n).sort(function(e,n){return Number(e)-Number(n)})[0];if(i&&n[i])return n[i]}var t=Object.keys(e).filter(function(e){return/^\d+$/.test(e)}).sort(function(e,n){return Number(e)-Number(n)});if(t.length&&e[t[0]])return e[t[0]];var o=null==e?void 0:e.deviations;if(o&&"object"==typeof o){var r=Object.keys(o).sort(function(e,n){return Number(e)-Number(n)})[0];if(r&&o[r])return o[r]}return null}(n);return i?e.__assign(e.__assign({},n),{deviation_summary:(null==n?void 0:n.deviation_summary)||(null==i?void 0:i.deviation_summary),deviation_title:(null==n?void 0:n.deviation_title)||(null==i?void 0:i.deviation_title),deviation_impact:(null==n?void 0:n.deviation_impact)||(null==i?void 0:i.deviation_impact),deviation_explanation:(null==n?void 0:n.deviation_explanation)||(null==i?void 0:i.deviation_explanation),evaluation_outputs:(null==n?void 0:n.evaluation_outputs)||(null==i?void 0:i.evaluation_outputs),cognitive_decisioning:(null==n?void 0:n.cognitive_decisioning)||(null==i?void 0:i.cognitive_decisioning)}):n};if(!("string"==typeof o&&o.includes(u.DEVIATION_BADGE_SEPARATOR)))return s(l);var a=o.split(u.DEVIATION_BADGE_SEPARATOR)[1];if(!a)return l;var c=(null==i?void 0:i.evaluationResult)||(null==t?void 0:t.evaluationResult)||{},d=(null===(n=null==c?void 0:c.deviation_entries)||void 0===n?void 0:n[a])||(null===(r=null==c?void 0:c.deviations)||void 0===r?void 0:r[a])||null;return d?e.__assign(e.__assign(e.__assign({},c),d),{deviation_summary:(null==d?void 0:d.deviation_summary)||(null==c?void 0:c.deviation_summary),deviation_title:(null==d?void 0:d.deviation_title)||(null==c?void 0:c.deviation_title),deviation_impact:(null==d?void 0:d.deviation_impact)||(null==c?void 0:c.deviation_impact),deviation_explanation:(null==d?void 0:d.deviation_explanation)||(null==c?void 0:c.deviation_explanation),evaluation_outputs:(null==d?void 0:d.evaluation_outputs)||(null==c?void 0:c.evaluation_outputs),cognitive_decisioning:(null==d?void 0:d.cognitive_decisioning)||(null==c?void 0:c.cognitive_decisioning)}):s(l)}(),y=(null!==(g=null===(v=null===(f=null==b?void 0:b.cognitive_decisioning)||void 0===f?void 0:f.decisioning_factors)||void 0===v?void 0:v.length)&&void 0!==g?g:0)>0||(null!==(m=null===(h=null===(p=null==b?void 0:b.cognitive_decisioning)||void 0===p?void 0:p.gaps_in_decision)||void 0===h?void 0:h.length)&&void 0!==m?m:0)>0,C=null!==(S=null==Ce?void 0:Ce.isLoading)&&void 0!==S&&S,E=!0;if(fi){var A=null==b?void 0:b.deviation_highlights;if(A&&"object"==typeof A)E=Object.values(A).some(function(e){return Array.isArray(e)&&e.length>0});else E=!1}return{isLoading:C&&!y,open:!0,sectionTitle:(null==i?void 0:i.title)?null==i?void 0:i.title:"No Counterpart",refSectionTitle:(null==t?void 0:t.title)?null==t?void 0:t.title:"No Counterpart",cognitiveData:x,anchorEl:n,sectionAnchorEl:_,badgeStyle:l||null,sectionIdx:o,docData:Ft,deviationData:b,isOrphan:!!r,hasGuidelineMatches:E}},[Ft,null==Ce?void 0:Ce.isLoading,fi]),qt=i.useCallback(function(e,n,i,t,o,r){var l;if(e.stopPropagation(),qn.open&&qn.sectionIdx===o)Zn();else{var s=e.currentTarget,a="left";(null===(l=wn.current)||void 0===l?void 0:l.contains(s))&&(a="right");Zi(),Yi.current&&et(),en(new Set),on([]),Rn.current=[],Qn(),zn.open?po():Un(),requestAnimationFrame(function(){var e=function(){var e,n,i,t;if("string"==typeof o&&o.includes(u.DEVIATION_BADGE_SEPARATOR)){var r=o.split(u.DEVIATION_BADGE_SEPARATOR),l="".concat(r[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(r[1]);return"right"===a?null===(e=Bi.current[l])||void 0===e?void 0:e.current:null===(n=wi.current[l])||void 0===n?void 0:n.current}return"right"===a?null===(i=Bi.current[o])||void 0===i?void 0:i.current:null===(t=wi.current[o])||void 0===t?void 0:t.current}()||s;Gn(Lt(e,n,t,o,i,r))})}},[qn.open,qn.sectionIdx,Zn,Un,Lt]),Gt=i.useCallback(function(){var e=qn.sectionIdx;qn.isOrphan,Zn(),Un(),null!==e&&(ct(e),Zi(),Yi.current&&et(),on([]),Rn.current=[],fi&&null!==e&&cn(fo(e)),en(function(n){return n.has(e)?new Set:new Set([e])}),setTimeout(function(){xn.current&&xn.current()},50))},[qn.sectionIdx,qn.isOrphan,Zn,Un,et]),Ht=i.useCallback(function(){var e=pn.current;if(e){pn.current=null;var n=pi.findIndex(function(n){return n.id===e}),i=hi.findIndex(function(n){return n.id===e}),t=-1===n?u.findKeyPathByNodeId(pi,e):null,o=-1===i?u.findKeyPathByNodeId(hi,e):null,r=-1!==n?n:t?Number(t.split("-")[0]):-1,l=-1!==i?i:o?Number(o.split("-")[0]):-1,s=function(e,n,i,t){var o,r,l,u;return-1!==e?null!==(r=null===(o=i.current[e])||void 0===o?void 0:o.current)&&void 0!==r?r:null:n&&null!==(u=null===(l=t.current[n])||void 0===l?void 0:l.current)&&void 0!==u?u:null},a=function(e,n,i){void 0===i&&(i=30);var t=0,o=function(){var r=e();r&&0!==r.getBoundingClientRect().height?(Qi.current.add(r),u.scrollAndHighlightClause(r,n)):t++<i&&requestAnimationFrame(o)};requestAnimationFrame(o)};if(qe)-1!==r&&jn.current&&a(function(){return s(n,t,Ti,Oi)},jn.current),-1!==l&&wn.current&&a(function(){return s(i,o,Ii,Fi)},wn.current);else{var c=Tn.current;if(!c)return;a(function(){return-1!==r?s(n,t,Ti,Oi):s(i,o,Ii,Fi)},c)}}},[pi,hi,qe,Ti,Ii,Oi,Fi,jn,wn,Tn]),Vt=i.useCallback(function(n){if(n){Zi(),et(),en(new Set),on([]),Rn.current=[],Un(),Qn();var i=pi.findIndex(function(e){return e.id===n}),t=hi.findIndex(function(e){return e.id===n}),o=-1===i?u.findKeyPathByNodeId(pi,n):null,r=-1===t?u.findKeyPathByNodeId(hi,n):null;if(-1!==i||o||-1!==t||r){var l=-1!==i?i:o?Number(o.split("-")[0]):-1,s=-1!==t?t:r?Number(r.split("-")[0]):-1;pn.current=n,rt(function(n){var i,t=e.__assign({},n),o=!1;-1!==l&&(t[i=qe?"left-".concat(l):String(l)]||(t[i]=!0,o=!0));-1!==s&&(t[i=qe?"right-".concat(s):String(s)]||(t[i]=!0,o=!0));return o?t:n}),ut(function(n){var i=e.__assign({},n),t=!1,l=function(e){for(var n=e.split("-"),o=n[0],r=1;r<n.length;r++)o+="-".concat(n[r]),i[o]||(i[o]=!0,t=!0)};return o&&l(o),r&&l(r),t?i:n}),setTimeout(function(){requestAnimationFrame(function(){pn.current===n&&Wt.current()})},50)}else console.warn('scrollToAndHighlightClause: nodeId "'.concat(n,'" not found'))}},[pi,hi,qe,rt,ut,et,Un,Qn]),Wt=i.useRef(Ht);i.useEffect(function(){Wt.current=Ht},[Ht]);var zt=i.useRef(null);i.useEffect(function(){if(ii){var e=ei.fields.find(function(e){return e.analysisKey===ii||e.key===ii});if(e){var n=Ei.current[e.key]||Ai.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[ii,ei.fields]);var Kt=i.useCallback(function(e){var n,i,t,o,r,l,u,s,a,c=null===(n=null==gt?void 0:gt.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!c||!c[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var d=c[e],f=(null==d?void 0:d.relation)||(null===(t=null===(i=null==d?void 0:d.highlights)||void 0===i?void 0:i.ruleA_spans)||void 0===t?void 0:t.length)||(null===(r=null===(o=null==d?void 0:d.highlights)||void 0===o?void 0:o.ruleB_spans)||void 0===r?void 0:r.length)||(null==d?void 0:d.mappings)&&d.mappings.length>0;if(d.mappings){var v=d.mappings[0]||{};return{score:d.score,relation:v.relation||"",highlightsA:(null===(l=v.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(u=v.highlights)||void 0===u?void 0:u.ruleB_spans)||[],hasContent:!!f}}return{score:d.score,relation:d.relation||"",highlightsA:(null===(s=d.highlights)||void 0===s?void 0:s.ruleA_spans)||[],highlightsB:(null===(a=d.highlights)||void 0===a?void 0:a.ruleB_spans)||[],hasContent:!!f}},[gt]),Ut=E.useStyleHelpers({proposedSections:pi,existingSections:hi,maintainRelativeOrder:qe,cognitiveMap:En,deviationData:Cn,treeData:me,resolvedComparisonConfig:ei,badgeStyleOverride:Pe}),Yt=Ut.getSectionCompareStyle,Jt=Ut.getSubSectionCompareStyle,Xt=Ut.getDeviationStyleByKey,$t=T.useLinesCalculator({containerRef:fn,leftContainerRef:jn,rightContainerRef:wn,svgContainerRef:dn,pathRefs:Sn,leftHeaderRef:vn,rightHeaderRef:gn,proposedSections:pi,existingSections:hi,visibleFields:mi,leftRefs:Ei,rightRefs:Ai,sectionLeftRefs:Ti,sectionRightRefs:Ii,subSectionLeftRefs:Oi,subSectionRightRefs:Fi,lhsBadgeRefs:wi,rhsBadgeRefs:Bi,sectionRowRefs:ji,expandedSections:ot,expandedSubSections:lt,connectedSections:Ze,isSideBySide:Li,activeSideBySideSection:zi,maintainRelativeOrder:qe,isGuidelineMode:fi,cognitiveMap:En,getSectionCompareStyle:Yt,getSubSectionCompareStyle:Jt,getDeviationStyleByKey:Xt,isArrowVisible:qi,isAnimatingRef:hn,isSideBySideRef:Yi,sideBySideCacheRef:Ui,sideBySideLineRef:$i,activeSideBySideSectionRef:Xi,activeSideBySideRightSectionRef:Ji,connectedLines:tn,setConnectedLines:on,cachedConnectedPositions:Rn,calculateLinesRef:xn,resizeTimerRef:_n,scrollLock:Ki,scrollSyncLocked:ln,handleResizeRef:bn,activeProposed:vi,existingRule:gi,analysisData:gt,pendingScrollTargetRef:Pn,pendingScrollCallbackRef:kn,resolvedComparisonConfig:ei,getFieldData:Kt}),Qt=$t.lines,Zt=$t.setLines,eo=$t.overallConnector,no=$t.setOverallConnector,io=$t.svgDimensions,to=$t.handleColumnScroll;i.useEffect(function(){zn.anchorEl&&requestAnimationFrame(function(){requestAnimationFrame(function(){var e;null===(e=xn.current)||void 0===e||e.call(xn)})})},[zn.anchorEl,ln]);var oo=i.useCallback(function(){Zi(),un(!1),rt({}),ut({}),et(),en(new Set),on([]),Rn.current=[],Un(),Qn(),Zn(),requestAnimationFrame(function(){xn.current&&xn.current()})},[rt,ut,et,Un,Qn,Zn]);i.useEffect(function(){Li||0!==Ze.size||un(!1)},[Li,Ze]);var ro=i.useMemo(function(){return Object.values(ot).some(Boolean)||Object.values(lt).some(Boolean)},[ot,lt]),lo=i.useRef(null),uo=i.useRef(0),so=i.useRef(0),ao=i.useRef(0),co=A.useResizeHandler({timerRef:lo,ruleComponentRef:In,scrollContainerRef:Tn,containerRef:fn,maintainRelativeOrder:qe,proposedSections:pi,existingSections:hi,isSideBySideRef:Yi,activeSideBySideSectionRef:Xi,activeSideBySideRightSectionRef:Ji,sectionRowRefs:ji,sectionRightRowRefs:Di,sectionLeftRefs:Ti,sectionRightRefs:Ii,subSectionLeftRefs:Oi,subSectionRightRefs:Fi,lhsBadgeRefs:wi,rhsBadgeRefs:Bi,leftContainerRef:jn,rightContainerRef:wn,calculateLinesRef:xn,handleResizeRef:bn,setIsResizing:Vi,setIsArrowVisible:Gi,sideBySideCacheRef:Ui,cachedConnectedPositions:Rn}).handleResize;i.useEffect(function(){bn.current=co},[co,bn]),i.useEffect(function(){var e=function(e,n,i,t,o){n.current=e.getBoundingClientRect().width;var r=new ResizeObserver(function(e){null!==i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(function(){var r,l,u;i.current=null;var s=e[e.length-1];if(s){var a=null!==(u=null===(l=null===(r=s.borderBoxSize)||void 0===r?void 0:r[0])||void 0===l?void 0:l.inlineSize)&&void 0!==u?u:s.contentRect.width;Math.abs(a-n.current)<1?o():(n.current=a,t())}})});return r.observe(e),r},n={current:null},i={current:null},t={current:null},o=[],r=[n,i,t];return In.current&&o.push(e(In.current,uo,n,function(){return bn.current()},function(){})),Tn.current&&o.push(e(Tn.current,so,i,function(){return bn.current()},function(){return xn.current()})),fn.current&&o.push(e(fn.current,ao,t,function(){return bn.current()},function(){return xn.current()})),function(){o.forEach(function(e){return e.disconnect()}),r.forEach(function(e){null!==e.current&&(cancelAnimationFrame(e.current),e.current=null)})}},[]),i.useEffect(function(){Yi.current=Li},[Li]),i.useEffect(function(){Xi.current=zi},[zi]);var fo=i.useCallback(function(e){var n,i,t,o,r,l="",s="0";if("number"==typeof e)l=(null===(n=pi[e])||void 0===n?void 0:n.nodeId)||(null===(i=pi[e])||void 0===i?void 0:i.id)||"";else{var a=String(e).split(u.DEVIATION_BADGE_SEPARATOR);l=a[0],s=a[1]||"0"}var c=null===(t=null==Cn?void 0:Cn[l])||void 0===t?void 0:t.evaluation_result,d=Array.isArray(c)?c[parseInt(s,10)]:null==c?void 0:c[s];return!1===(null===(r=null===(o=null==d?void 0:d.evaluation_outputs)||void 0===o?void 0:o.guideline_flag)||void 0===r?void 0:r.rulebook_used)?1:0},[pi,Cn]),vo=i.useCallback(function(e){var n,i,t=jn.current,o=wn.current,r=O.getVisibleGuidelineTargets(o),l="string"==typeof e&&e.includes(u.DEVIATION_BADGE_SEPARATOR),s=e;if(l){var a=e.split(u.DEVIATION_BADGE_SEPARATOR);a.length>=2&&(s="".concat(a[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(a[1]))}var c=(null===(n=wi.current[s])||void 0===n?void 0:n.current)||(null===(i=wi.current[e])||void 0===i?void 0:i.current);if(r.length>0&&c&&t&&o){var d=r[0];On.current&&(On.current.style.height="0px"),Bn.current&&(Bn.current.style.height="0px"),Fn.current&&(Fn.current.style.height="0px"),Dn.current&&(Dn.current.style.height="0px"),requestAnimationFrame(function(){var e=c.getBoundingClientRect(),n=d.getBoundingClientRect(),i=t.getBoundingClientRect(),r=o.getBoundingClientRect(),l=t.scrollTop+(e.top-i.top)+e.height/2,u=o.scrollTop+(n.top-r.top)+n.height/2,s=l-i.height/2,a=Math.max(0,s),f=t.scrollHeight-t.clientHeight,v=a>f?a-f:0,g=i.top+l-a,p=r.top+u-g,h=0;p<0&&(h=Math.abs(p),p=0);var m=o.scrollHeight-o.clientHeight+h,S=p>m?p-m:0;Fn.current&&(Fn.current.style.height="".concat(v,"px")),Bn.current&&(Bn.current.style.height="".concat(h,"px")),Dn.current&&(Dn.current.style.height="".concat(S,"px")),requestAnimationFrame(function(){t.scrollTo({top:a,behavior:"smooth"}),o.scrollTo({top:p,behavior:"smooth"}),xn.current&&setTimeout(function(){return xn.current()},50)})})}},[u.DEVIATION_BADGE_SEPARATOR]),go=i.useCallback(function(){var e,n=qn.sectionIdx,i=qn.isOrphan;if(Un(),null!=n){var t="left";qn.anchorEl&&(null===(e=wn.current)||void 0===e?void 0:e.contains(qn.anchorEl))&&(t="right"),ct(n),fi&&(cn(fo(n)),en(new Set([n]))),nt(n,i,{sourceSide:t,onReady:function(){fi&&setTimeout(function(){return vo(String(n))},150)}})}},[nt,qn.isOrphan,qn.sectionIdx,qn.anchorEl,Un,ct,fi,vo,fo]),po=i.useCallback(function(){Un(),et(),en(new Set),on([]),Rn.current=[]},[Un,et]),ho=null!==qn.sectionIdx&&Ze.has(qn.sectionIdx),mo=S.useDeviationNavigation({proposedSections:pi,existingSections:hi,parentDeviationRecord:Si,expandedSections:ot,maintainRelativeOrder:!!qe,scrollContainerRef:Tn,leftContainerRef:jn,rightContainerRef:wn,lhsBadgeRefs:wi,rhsBadgeRefs:Bi}),So=mo.showDeviationNavigation,Ro=mo.showOpenNodeRef,xo=mo.adjustScrollForPopup,_o=i.useCallback(function(e,n,i,t,o){var r,l="string"==typeof t?u.safeStringify(t).trim():u.safeStringify(null==t?void 0:t.deviation_summary).trim(),s=e.currentTarget;Qn();var a="left";(null===(r=wn.current)||void 0===r?void 0:r.contains(s))&&(a="right");var c=function(){var e,i,t,o;if("string"==typeof n&&n.includes(u.DEVIATION_BADGE_SEPARATOR)){var r=n.split(u.DEVIATION_BADGE_SEPARATOR),l="".concat(r[0]).concat(u.DEVIATION_BADGE_SEPARATOR).concat(r[1]);return"right"===a?null===(e=Bi.current[l])||void 0===e?void 0:e.current:null===(i=wi.current[l])||void 0===i?void 0:i.current}return"right"===a?null===(t=Bi.current[n])||void 0===t?void 0:t.current:null===(o=wi.current[n])||void 0===o?void 0:o.current};if(i&&!fi)return et(),en(new Set),on([]),Rn.current=[],void(l&&(ct(n),requestAnimationFrame(function(){var e=c()||s;e&&(e.getBoundingClientRect().top>.8*window.innerHeight&&e.scrollIntoView({behavior:"smooth",block:"center"}));Kn({open:!0,anchorEl:e,summary:t,displayImpact:o})})));ct(n),fi&&(cn(fo(n)),en(new Set([n]))),l?setTimeout(function(){nt(n,i,{toggleIfSame:!1,sourceSide:a,onReady:function(){var e,i,r,l=c()||s;if(fi)setTimeout(function(){return vo(n)},150);else if(l){var u=l.getBoundingClientRect();if(u.top>.8*window.innerHeight||u.top<100){var a=u.top-window.innerHeight/2;qe?(null===(e=jn.current)||void 0===e||e.scrollBy({top:a,behavior:"smooth"}),null===(i=wn.current)||void 0===i||i.scrollBy({top:a,behavior:"smooth"})):null===(r=Tn.current)||void 0===r||r.scrollBy({top:a,behavior:"smooth"})}}Kn({open:!0,anchorEl:l,summary:t,displayImpact:o})}})},350):setTimeout(function(){nt(n,i,{toggleIfSame:!1,sourceSide:a}),fi&&setTimeout(function(){return vo(n)},150)},350)},[nt,Qn,Kn,et,ct,fi,qe,vo,Cn]),bo=i.useMemo(function(){var e;if(!we)return null;var n=null===(e=null==we?void 0:we.id)||void 0===e?void 0:e.split(":")[0];for(var i in Si){if((Si[i]||[]).some(function(e){return e.id===n}))return i}return null},[we,Si]),yo=i.useRef({id:null,triggerMs:null}),Co=i.useRef(null);i.useEffect(function(){if(null==we?void 0:we.id){var n=Number(we.trigger),i=yo.current;if((null==i?void 0:i.id)!==we.id||(null==i?void 0:i.triggerMs)!==n){if(we.id.includes(":")&&/:\d+$/.test(we.id)){var t=we.id.split(":"),o=t[0],r=t[1],l=null!=r?r:"0",s="".concat(we.id,":").concat(n);Co.current!==s&&(Un(),Qn(),et(),en(new Set),on([]),Rn.current=[],Co.current=s);var a=!1,c=0,d=null,f=null,v=!1,g=function(e,n){for(var i=function(e,t){if(!e)return null;if(n.includes(e.id)||n.includes(e.nodeId)||n.includes(e.contentId))return t;if(!Array.isArray(e.subsections))return null;for(var o=0;o<e.subsections.length;o++){var r=i(e.subsections[o],"".concat(t,"-").concat(o));if(r)return r}return null},t=0;t<e.length;t++){var o=i(e[t],String(t));if(o)return o}return null},p=function(){var i,t,r;if(!a){var s=function(){yo.current={id:we.id,triggerMs:n}},h=null,m=null;for(var S in Si){var R=Si[S].find(function(e){var n;return e.id===o||e.nodeId===o||e.contentId===o||(null===(n=e.evaluationResult)||void 0===n?void 0:n.nodeId)===o});if(R){h=S,m=R;break}}if(m&&h){var x=Array.from(new Set([o,m.id,m.nodeId,m.contentId,null===(i=m.evaluationResult)||void 0===i?void 0:i.nodeId].filter(Boolean))),_=pi.findIndex(function(e){return e.id===h}),b=hi.findIndex(function(e){return e.id===h}),y=-1===_&&-1!==b,C=g(pi,x),E=g(hi,x);if(C&&!E&&!y){var A=C.split("-"),T=Number(A[0]);if(qe){var I=null===(r=null===(t=pi[T])||void 0===t?void 0:t.refIndexes)||void 0===r?void 0:r[0],w=hi.findIndex(function(e){return e.selfIndex===I});-1!==w&&(T=w)}E=e.__spreadArray([T],A.slice(1),!0).join("-")}if(C||E){var B=C?Number(C.split("-")[0]):_,D=E?Number(E.split("-")[0]):b,O=D>=0?D:E?Number(E.split("-")[0]):-1,F=pi[B],j=hi[O],P=F&&!F.title&&!F.content,k=j&&!j.title&&!j.content,N=y||(!C&&!!E||P&&!k);if(N){if(!(qe?!!Po.current["right-".concat(D)]:!!Po.current[String(D)])&&D>=0)return at(D,"right"),void(d=setTimeout(p,200))}else if(!(qe?!!Po.current["left-".concat(B)]:!!Po.current[String(B)])&&B>=0)return at(B,"left"),void(d=setTimeout(p,200));var M=C||"",L=E||"",q=x.map(function(e){return"".concat(e).concat(u.DEVIATION_BADGE_SEPARATOR).concat(l)}),G=q[0],H=function(){for(var e,n,i=0,t=q;i<t.length;i++){var o=t[i],r=(null===(e=wi.current[o])||void 0===e?void 0:e.current)||null,l=(null===(n=Bi.current[o])||void 0===n?void 0:n.current)||null;if(r||l)return{refId:o,left:r,right:l}}return{refId:G,left:null,right:null}},V=function(e){return"".concat(e).concat(u.DEVIATION_BADGE_SEPARATOR).concat(M).concat(u.DEVIATION_BADGE_SEPARATOR).concat(L)};if(!v){ct(V(G)),v=!0,c=0;var W=function(){var e=H(),n=e.left,i=e.right;return N||!n&&!!i?i:n};return null==f||f(),void(d=setTimeout(function(){var e,n,i,t,o,r,l,u;a||(e=W,n=function(){a||(f=null,p())},t=0,o=null,r=null,l=performance.now(),u=function(){if(!a)if(performance.now()-l>3e3)n();else{var s=e();if(s&&0!==s.getBoundingClientRect().height){var c=s.getBoundingClientRect(),d=c.top,f=c.height,v=null!==o&&Math.abs(d-o)<.5,g=null!==r&&Math.abs(f-r)<.5;if(v&&g){if(++t>=5)return void n()}else t=0;o=d,r=f,i=requestAnimationFrame(u)}else i=requestAnimationFrame(u)}},i=requestAnimationFrame(u),f=function(){return cancelAnimationFrame(i)})},300))}var z=H(),K=z.refId,U=z.left,Y=z.right,J=V(K);if(U||Y){var X=N||!U&&!!Y,$=X?Y:U,Q=qe?X?wn.current:jn.current:Tn.current;if($&&Q){var Z=$.getBoundingClientRect();if(0!==Z.height){var ee=Q.getBoundingClientRect(),ne=Z.top-ee.top+Q.scrollTop-ee.height/2+Z.height/2,ie=(null==C?void 0:C.includes("-"))||(null==E?void 0:E.includes("-")),te=function(){return e.__awaiter(void 0,void 0,void 0,function(){var n,i,t,o,r,c,d,f,v,g;return e.__generator(this,function(p){switch(p.label){case 0:return a?[2]:(s(),n=$ instanceof Element?window.getComputedStyle($).color:"",[U,Y].forEach(function(e){e&&(e.style.transition="box-shadow 300ms ease-in-out",e.style.boxShadow="0 0 10px ".concat(n))}),setTimeout(function(){[U,Y].forEach(function(e){e&&(e.style.boxShadow="")})},2e3),i=(null===(d=null===(c=m.evaluationResult)||void 0===c?void 0:c.deviations)||void 0===d?void 0:d[l])||m,t=(null===(f=m.evaluationResult)||void 0===f?void 0:f.evaluation_outputs)||m.evaluation_outputs,!!U&&!!Y||fi?(r=function(e,n){return Promise.race([e,new Promise(function(e){return setTimeout(e,n)})])},qe?[4,Promise.all([jn.current?r(u.waitForScrollIdle(jn.current),600):Promise.resolve(),wn.current?r(u.waitForScrollIdle(wn.current),600):Promise.resolve()])]:[3,2]):(o=X?(null===(v=Bi.current[ie?K:D])||void 0===v?void 0:v.current)||Y:(null===(g=wi.current[ie?K:B])||void 0===g?void 0:g.current)||U,xo(o,function(){Kn({open:!0,anchorEl:o,displayImpact:we.displayImpact,summary:e.__assign(e.__assign({},i),{evaluation_outputs:t})})},{skipScroll:!0}),null==Be||Be(),[2]));case 1:p.sent(),p.label=2;case 2:return fi&&(cn(fo(J)),en(new Set([J]))),it.current(J,!1,{toggleIfSame:!1,sourceSide:y?"right":"left",onReady:function(){var n,t,o,r;s();var l=X?(null===(n=Bi.current[K])||void 0===n?void 0:n.current)||Y:(null===(t=wi.current[K])||void 0===t?void 0:t.current)||U;if(fi)setTimeout(function(){return vo(J)},150);else{var u=(null===(o=wi.current[K])||void 0===o?void 0:o.current)||U,a=(null===(r=Bi.current[K])||void 0===r?void 0:r.current)||Y;u&&(u.style.scrollMarginTop="150px",u.scrollIntoView({behavior:"smooth",block:"start"})),a&&(a.style.scrollMarginTop="150px",a.scrollIntoView({behavior:"smooth",block:"start"}))}Kn({open:!0,anchorEl:l,displayImpact:we.displayImpact,summary:e.__assign({},i)}),null==Be||Be()}}),[2]}})})};Math.abs(Q.scrollTop-ne)<=2?te():u.scrollAndWait(Q,ne,te)}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}else++c<30&&(d=setTimeout(p,100))}};return d=setTimeout(p,100),function(){a=!0,d&&clearTimeout(d),null==f||f()}}yo.current={id:we.id,triggerMs:n},Vt(we.id);var h=pi.findIndex(function(e){return e.id===we.id}),m=hi.findIndex(function(e){return e.id===we.id});-1===h&&-1===m||setTimeout(function(){var e=-1!==h?h:m,n=-1===h;fi&&cn(fo(e)),en(new Set([e])),it.current(e,n,{sourceSide:n?"right":"left",onReady:function(){fi&&setTimeout(function(){return vo(String(e))},150)}})},400)}}},[null==we?void 0:we.id,null==we?void 0:we.trigger,null==we?void 0:we.displayImpact,Si,pi,hi,qe,Kn,Vt,fi,fo,vo]),i.useEffect(function(){var n,i,t;if(zn.open){var o=zn.anchorEl;if(o&&!o.isConnected){var r=function(e){for(var n,i=0,t=Object.entries(e);i<t.length;i++){var r=t[i],l=r[0];if((null===(n=r[1].current)||void 0===n?void 0:n.textContent)===o.textContent)return l}return null},l=(null===(n=o.dataset)||void 0===n?void 0:n.deviationRefId)||r(wi.current)||r(Bi.current);if(l){var u=(null===(i=Bi.current[l])||void 0===i?void 0:i.current)||(null===(t=wi.current[l])||void 0===t?void 0:t.current);u&&u.isConnected&&Kn(function(n){return e.__assign(e.__assign({},n),{anchorEl:u})})}}}},[zn.open,zn.anchorEl,ln,Ze,ot]);var Eo=Mn.open,Ao=Mn.sectionIdx,To=Mn.isOrphan,Io=Mn.badgeStyle,wo=Mn.anchorEl,Bo=Mn.sectionAnchorEl;i.useEffect(function(){var n;if(Ce.isStreamingEnabled&&Eo&&null!=Ao&&Ao!==mt){var i="string"==typeof Ao?Ao.split(u.DEVIATION_BADGE_SEPARATOR)[0]:null,t=function(e,n){var i;if(!e||!Array.isArray(e))return null;for(var o=0,r=e;o<r.length;o++){var l=r[o];if(l.id===n)return l;if(null===(i=l.subsections)||void 0===i?void 0:i.length){var u=t(l.subsections,n);if(u)return u}}return null},o=i&&"string"==typeof i?t(pi,i):null,r=i&&"string"==typeof i?t(hi,i):null,l="number"==typeof Ao?pi[Ao]||null:o||i&&((null===(n=null==me?void 0:me.nodes)||void 0===n?void 0:n[i])||(null==me?void 0:me[i]))||null,s="number"==typeof Ao?hi[Ao]||null:r,a=Lt(wo,l,s,Ao,To,Io);Ln(function(n){return n.open?u.safeStringify(n.cognitiveData)===u.safeStringify(a.cognitiveData)&&u.safeStringify(n.deviationData)===u.safeStringify(a.deviationData)&&n.sectionTitle===a.sectionTitle&&n.refSectionTitle===a.refSectionTitle?n:e.__assign(e.__assign(e.__assign({},n),a),{open:!0,anchorEl:n.anchorEl,sectionAnchorEl:n.sectionAnchorEl}):n})}},[Eo,Ao,To,Io,wo,Bo,pi,hi,Lt]);var Do=i.useCallback(function(e){var i=e.section,t=e.keyPath,o=e.depth,r=void 0===o?0:o,l=e.columnKey,u=void 0===l?"left":l,s=e.parentNodeId,a=void 0===s?"":s,c=e.sectionOffset,d=e.rhsOrphanVisualIndexes;return n.jsx(x.default,{section:i,keyPath:t,depth:r,columnKey:u,parentNodeId:a,sectionOffset:c,rhsOrphanVisualIndexes:d})},[]),Oo=i.useMemo(function(){return pi.map(function(e,i){var t,o,r=!(null==e?void 0:e.title)&&!(null==e?void 0:e.content),l=!(null==e?void 0:e.refIndexes)||0===e.refIndexes.length;return r&&l&&qe?null:n.jsx(_.default,{section:e,idx:i},null!==(o=null!==(t=null==e?void 0:e.layoutKey)&&void 0!==t?t:null==e?void 0:e.id)&&void 0!==o?o:"left-row-".concat(i))})},[pi,qe]),Fo=i.useMemo(function(){return hi.map(function(e,i){var t,o,r=!(null==e?void 0:e.title)&&!(null==e?void 0:e.content),l=!(null==e?void 0:e.refIndexes)||0===e.refIndexes.length;return r&&l&&qe?null:n.jsx(b.default,{section:e,idx:i},null!==(o=null!==(t=null==e?void 0:e.layoutKey)&&void 0!==t?t:null==e?void 0:e.id)&&void 0!==o?o:"right-row-".concat(i))})},[hi,qe]),jo=i.useRef(qt);i.useEffect(function(){jo.current=qt},[qt]);var Po=i.useRef(ot);i.useEffect(function(){Po.current=ot},[ot]);var ko=i.useRef(_o);i.useEffect(function(){ko.current=_o},[_o]);var No=i.useRef(po);i.useEffect(function(){No.current=po},[po]);var Mo=i.useRef(at);i.useEffect(function(){Mo.current=at},[at]);var Lo=i.useRef(st);i.useEffect(function(){Lo.current=st},[st]);var qo=i.useRef(Do);i.useEffect(function(){qo.current=Do},[Do]);var Go=i.useRef(et);i.useEffect(function(){Go.current=et},[et]);var Ho=i.useMemo(function(){return{isGuidelineMode:fi,maintainRelativeOrder:!!qe,showDeviationBadges:We,isProposingFix:Oe,proposingFixNodeId:Fe,isRedlineFlow:je,isSideBySide:Li,activeSideBySideSection:zi,scrollSyncLocked:ln,toggleScrollSyncLocked:ft,summaryPopupAnchorEl:zn.anchorEl,connectedSections:Ze,proposedSections:pi,existingSections:hi,deviationNumberRegistry:Ri,deviationParentRegistry:xi,treeData:me,displayConfig:Ce,resolvedMarkdownStyles:An,unifiedNumbering:vt,expandedSections:ot,expandedSubSections:lt,setExpandedSubSections:ut,getSectionCompareStyle:Yt,getSubSectionCompareStyle:Jt,getBadgeRef:Ni,getSectionRowRef:Pi,getSubSectionRef:ki,sectionLeftRefs:Ti,sectionRightRefs:Ii,sectionRowRefs:ji,sectionRightRowRefs:Di,subSectionLeftRefs:Oi,subSectionRightRefs:Fi,lhsBadgeRefs:wi,rhsBadgeRefs:Bi,openMoreFunctionsPopup:Ct,handleOpenSummaryPopup:Et,openSummaryPopup:Et,handleCloseSummaryPopup:At,toggleSection:Tt,handleSubSectionToggle:It,renderSubSectionAccordion:wt,resetSideBySide:Bt,setConnectedSections:en,setConnectedLines:on,cachedConnectedPositions:Rn,showDeviationNavigation:So,showOpenNodeRef:Ro,deviationNodeIdToView:null==we?void 0:we.id,deviationTargetParentId:bo,guidelinesData:ke,gptWebCitationConfig:Me}},[fi,qe,We,Oe,Fe,je,Li,zi,ln,ft,zn.anchorEl,Ze,pi,hi,Ri,Ce,An,vt,ot,lt,ut,Yt,Jt,Ni,Pi,ki,So,Ro,we,bo,ke,Me]),Vo=u.safeStringify(Mn.sectionTitle||ui||ri),Wo=u.safeStringify(fi?ai||ci||Mn.refSectionTitle:Mn.refSectionTitle||ai||ci);return n.jsx(C.CompareContextProvider,e.__assign({value:Ho},{children:n.jsxs(t.Box,e.__assign({ref:In,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[Ke&&n.jsx(t.Box,e.__assign({sx:{position:"absolute",inset:0,bgcolor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(10px)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"8px"}},{children:n.jsx(f.default,{})})),zn.open&&n.jsx(y.default,{open:zn.open,anchorEl:zn.anchorEl,containerEl:zt.current,clipTopEl:vn.current,scrollContainerEl:Tn.current,onClose:po,summary:zn.summary,displayImpact:zn.displayImpact,isScrollLocked:ln}),n.jsx(d.default,{open:qn.open,anchorEl:qn.anchorEl,maintainRelativeOrder:!!qe,sectionTitle:qn.sectionTitle,referenceSectionTitle:qn.refSectionTitle,onClose:Zn,onOpenCognitiveCompare:Xn,onOpenSideBySide:go,onConnect:Gt,isConnected:ho,isOrphan:!fi&&!!qn.isOrphan,isGuidelineMode:fi,hasGuidelineMatches:qn.hasGuidelineMatches}),Mn.open&&n.jsx(c.default,{open:Mn.open,popupRef:Jn,position:Hn,popupConfig:Ae,onClose:function(){Vn(null),Ln(function(n){return e.__assign(e.__assign({},n),{open:!1})}),Yn(null)},markdownStyles:_e,sectionTitle:Vo,referenceSectionTitle:Wo,cognitiveData:Mn.cognitiveData,anchorEl:Mn.anchorEl,sectionAnchorEl:Mn.sectionAnchorEl,scrollContainerEl:Tn.current,badgeStyle:Mn.badgeStyle,docData:Mn.docData,deviationData:Mn.deviationData,isLoading:Mn.isLoading}),n.jsx(t.Snackbar,e.__assign({open:!!Je,autoHideDuration:8e3,onClose:function(){return Xe(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(t.Alert,e.__assign({onClose:function(){return Xe(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:Je}))})),n.jsx(R.default,{componentHeaderText:he,displayConfig:Ce,maintainRelativeOrder:qe,onCollapseAll:oo,showCollapseAll:ro,onToggleView:function(e){Ue(!0),setTimeout(function(){Ge(!e),null==Ee||Ee(!e),un(!1),et(),Un(),en(new Set),on([]),Rn.current=[],requestAnimationFrame(function(){requestAnimationFrame(function(){setTimeout(function(){Ue(!1)},600)})})},50)}}),n.jsx(t.Box,e.__assign({ref:Tn,onScroll:to,sx:{flex:1,minHeight:0,pt:1.5,pb:1,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",overflowY:qe?"visible":"auto",borderTop:pt&&ht?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(t.Box,e.__assign({sx:e.__assign({display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"},qe?{flex:1}:{})},{children:n.jsxs(t.Box,e.__assign({ref:fn,sx:e.__assign({display:"grid",gridTemplateColumns:"minmax(0, 1fr) 180px minmax(0, 1fr)",gap:"100px",maxWidth:"1200px",width:"100%",position:"relative",minHeight:0},qe?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(w.default,{svgContainerRef:dn,svgDimensions:io,isResizing:Hi,overallConnector:eo,rootDeviationStyle:xt,lines:Qt,isSideBySide:Li,activeSideBySideSection:zi,isArrowVisible:qi,maintainRelativeOrder:qe,proposedSections:pi,existingSections:hi,cognitivePopup:Mn,activeBadgeId:Wn,closeCognitivePopup:Qn,setActiveBadgeId:Yn,openCognitivePopupFromState:$n,buildSectionPopupState:Lt,connectedLines:tn,isGuidelineMode:fi,pathRefs:Sn}),n.jsxs(t.Box,e.__assign({sx:e.__assign({border:"1px solid #E7E7E9",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)"},qe?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(t.Box,e.__assign({ref:vn,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E7E7E9",borderRadius:"8px 8px 0 0",display:"flex",alignItems:"center",minHeight:"40px",overflow:"hidden",minWidth:0}},{children:n.jsx(t.Tooltip,e.__assign({title:ri,placement:"top"},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,textAlign:"center",display:"block"}},{children:ri}))}))})),n.jsxs(t.Box,e.__assign({ref:jn,onScroll:to,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},qe?{maxHeight:"calc(100vh - 250px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,mr:"-180px",pr:"192px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:On,style:{width:"100%",height:"0px",flexShrink:0}}),bi&&Oo,n.jsx("div",{ref:Fn,style:{width:"100%",height:"0px",flexShrink:0}})]}))]})),n.jsx(t.Box,e.__assign({ref:zt,sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"15px",gap:0,zIndex:20,pointerEvents:"none"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(t.Box,e.__assign({onClick:function(n){n.stopPropagation(),Mn.open&&Wn===mt?Qn():(Yn(mt),$n(Lt(n.currentTarget,{title:Pt,content:"",evaluationResult:St,cognitiveData:{section_id:"",decisioning:[],gap:[],relevance_score:0,isMissingRationale:!0}},null,mt,!0,e.__assign(e.__assign({},xt),{label:""}))))},sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:"5px",top:"-8px",borderRadius:"20px",bgcolor:xt.badgeBg,color:xt.badgeText,border:"1px solid ".concat(xt.badgeBorder),fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",position:"relative",zIndex:1,pointerEvents:"auto",cursor:"pointer"}},{children:[null!=Rt?Rt:n.jsx(v.default,{}),n.jsx(t.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(r.ButtonCognitiveIcon,{})})),n.jsx(o.ChevronDown,{size:11,style:{transform:Mn.open&&Wn===mt?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.25s ease"}})]}))}))})),n.jsxs(t.Box,e.__assign({sx:e.__assign({border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0},qe?{flex:1,overflow:"visible",minHeight:0}:{})},{children:[Wi&&n.jsx(l.default,{sections:11}),n.jsx(t.Box,e.__assign({ref:gn,sx:e.__assign({p:"8px",bgcolor:fi?"#F1F3F5":"#F7F8FA",borderBottom:"1px solid #D7DCE2",borderRadius:"8px 8px 0 0",display:"flex",alignItems:"center"},qe?e.__assign({maxHeight:"calc(100vh - 250px)",overflowY:"auto",overflowX:"hidden",minHeight:0},fi?{"&::-webkit-scrollbar":{width:"6px",display:"block"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"#CBD5E1",borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:"#94A3B8"},scrollbarWidth:"thin",scrollbarColor:"#CBD5E1 transparent"}:{"&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}):{})},{children:fi?n.jsxs(t.Tabs,e.__assign({value:an,onChange:function(e,n){return cn(n)},variant:"fullWidth",TabIndicatorProps:{sx:{display:"none"}},sx:{width:"100%",minHeight:"36px","& .MuiTab-root":{minHeight:"36px",px:1,py:0,borderRadius:"8px",fontSize:"14px",lineHeight:1,fontWeight:500,textTransform:"none",color:"#374151",minWidth:0,transition:"background-color 160ms ease, box-shadow 160ms ease"},"& .Mui-selected":{color:"#374151",bgcolor:"#FFFFFF"}}},{children:[n.jsx(t.Tab,{label:n.jsx(t.Tooltip,e.__assign({title:ci,placement:"top"},{children:n.jsx(t.Box,e.__assign({component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",width:"100%"}},{children:"Redline Guidelines"}))}))}),n.jsx(t.Tab,{label:n.jsx(t.Tooltip,e.__assign({title:"Web & GPT Sources",placement:"top"},{children:n.jsx(t.Box,e.__assign({component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",width:"100%"}},{children:"Web & GPT Sources"}))}))})]})):n.jsx(t.Tooltip,e.__assign({title:ci,placement:"top"},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,textAlign:"center",display:"block"}},{children:ci}))}))})),n.jsxs(t.Box,e.__assign({ref:wn,onScroll:to,sx:e.__assign({p:fi?"0px":"12px",display:"flex",flexDirection:"column"},qe?e.__assign(e.__assign({maxHeight:"calc(100vh - 250px)"},!fi&&{flex:1}),{overflowY:"auto",overflowX:"hidden",minHeight:0,ml:"-150px",pl:"165px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}):{})},{children:[n.jsx("div",{ref:Bn,style:{width:"100%",height:"0px",flexShrink:0}}),fi?0===an?n.jsx(B.default,{guidelinesData:ke,deviationData:Ie,connectedSections:Ze,proposedSections:pi}):n.jsx(D.default,{deviationData:Ie,connectedSections:Ze,proposedSections:pi}):bi&&Fo,n.jsx("div",{ref:Dn,style:{width:"100%",height:"0px",flexShrink:0}})]}))]}))]}))}))}))]}))}))};
2
2
  //# sourceMappingURL=CognitiveCompare.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("react/jsx-runtime"),i=require("react"),o=require("@mui/material"),l=require("react-markdown"),t=require("rehype-raw"),a=require("../../CognitiveCompareConfig.js"),n=require("../../CognitiveComparehelpers.js"),u=require("../utils/processGuidelinesMarkdown.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=s(l),g=s(t);exports.default=function(l){var t=l.guidelinesData,s=l.deviationData,v=l.connectedSections,_=l.proposedSections,p=Array.from(v)[0],c=i.useMemo(function(){var r;if(null==p||!s)return{targetHighlights:[],labelColor:""};var i="";"number"==typeof p?i=(null===(r=_[p])||void 0===r?void 0:r.nodeId)||"":"string"==typeof p&&(i=p.includes(n.DEVIATION_BADGE_SEPARATOR)?p.split(n.DEVIATION_BADGE_SEPARATOR)[0]:p.split("::")[0].split(":")[0]);var o=s[i];if(!o)return{targetHighlights:[],labelColor:""};var l=[],t=o.evaluation_result||{},a="";return Object.values(t).forEach(function(r){var i,o,t,u,s;(null===(i=null==r?void 0:r.deviation_highlights)||void 0===i?void 0:i.rulebook_guidelines)&&(l=e.__spreadArray(e.__spreadArray([],l,!0),r.deviation_highlights.rulebook_guidelines,!0),a=(null===(t=null===(o=r.evaluation_outputs)||void 0===o?void 0:o.metadata)||void 0===t?void 0:t.label_color)?n.generateColorPalette(null===(s=null===(u=r.evaluation_outputs)||void 0===u?void 0:u.metadata)||void 0===s?void 0:s.label_color).bg:"")}),{targetHighlights:l.filter(Boolean),labelColor:a}},[p,s,_]),h=c.targetHighlights,f=c.labelColor,b=i.useMemo(function(){return u.processGuidelinesMarkdown({guidelinesData:t,targetHighlights:h,labelColor:f||"#FEF08A"})},[t,h,f]);return r.jsx(o.Box,e.__assign({sx:e.__assign(e.__assign({padding:"0px 12px",backgroundColor:"#FFFFFF",borderRadius:"8px"},a.SHARED_MARKDOWN_STYLES),{overflow:"visible"})},{children:r.jsx(d.default,e.__assign({rehypePlugins:[g.default]},{children:b}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("react/jsx-runtime"),i=require("react"),t=require("@mui/material"),l=require("react-markdown"),o=require("rehype-raw"),a=require("../../CognitiveCompareConfig.js"),n=require("../../CognitiveComparehelpers.js"),s=require("../utils/processGuidelinesMarkdown.js"),u=require("../utils/resolveGuidelineSelection.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g=d(l),c=d(o);exports.default=function(l){var o=l.guidelinesData,d=l.deviationData,p=l.connectedSections,f=l.proposedSections,h=Array.from(p)[0],v=i.useMemo(function(){if(null==h||!d)return{targetHighlights:[],labelColor:""};var e=u.resolveGuidelineSelection({activeIdentifier:h,deviationData:d,proposedSections:f}),r=e.labelColor?n.generateColorPalette(e.labelColor):null;return{targetHighlights:e.targetHighlights,labelColor:(null==r?void 0:r.bg)||""}},[h,d,f]),b=v.targetHighlights,C=v.labelColor,_=i.useMemo(function(){return s.processGuidelinesMarkdown({guidelinesData:o,targetHighlights:b,labelColor:C||"#FEF08A"})},[o,b,C]);return r.jsx(t.Box,e.__assign({sx:e.__assign(e.__assign({padding:"0px 12px",backgroundColor:"#FFFFFF",borderRadius:"8px"},a.SHARED_MARKDOWN_STYLES),{overflow:"visible"})},{children:r.jsx(g.default,e.__assign({rehypePlugins:[c.default]},{children:_}))}))};
2
2
  //# sourceMappingURL=GuidelinePanel.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("react/jsx-runtime"),n=require("react"),t=require("@mui/material"),a=require("react-markdown"),o=require("rehype-raw"),i=require("../../CognitiveCompareConfig.js"),u=require("../../CognitiveComparehelpers.js"),d=require("../../CitationAnchor.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(a),c=l(o),v=function(e){var r,n,t=e.evalNode;return!1===(null===(n=null===(r=null==t?void 0:t.evaluation_outputs)||void 0===r?void 0:r.guideline_flag)||void 0===n?void 0:n.rulebook_used)},p=function(e,r,n){return"".concat(e,"::").concat(r,"::").concat(n)},f=function(e,r){return"".concat(e,"::").concat(r)},y={relativeWrapper:{verticalAlign:"baseline"},arrow:{color:"#6D28D9"}};exports.default=function(a){var o=a.deviationData,l=a.connectedSections,b=a.proposedSections,w=Array.from(l||[])[0],_=n.useMemo(function(){return function(e,r){var n;return"number"==typeof e?(null===(n=r[e])||void 0===n?void 0:n.nodeId)||"":e&&"string"==typeof e&&e.trim()?e.includes(u.DEVIATION_BADGE_SEPARATOR)?e.split(u.DEVIATION_BADGE_SEPARATOR)[0]:e.split("::")[0].split(":")[0]:""}(w,b||[])},[w,b]),g=n.useMemo(function(){if(!o||"object"!=typeof o)return[];return Object.entries(o).flatMap(function(e){var r=e[0];return function(e){var r=e&&"object"==typeof e?e.evaluation_result:null;return!r||"object"!=typeof r&&!Array.isArray(r)?[]:Array.isArray(r)?r.map(function(e,r){return{evalNode:e,evaluationKey:String(r)}}):"object"==typeof r?Object.entries(r).map(function(e){var r=e[0];return{evalNode:e[1],evaluationKey:r}}):[]}(e[1]).filter(v).map(function(e){var n,t,a,o=e.evalNode,i=e.evaluationKey;return{nodeId:r,evaluationKey:i,answerKey:f(r,i),evaluation:o,webSearchAnswer:o.web_search_answer,colorPalette:null!==(a=u.generateColorPalette((null===(t=null===(n=null==o?void 0:o.evaluation_outputs)||void 0===n?void 0:n.metadata)||void 0===t?void 0:t.label_color)||""))&&void 0!==a?a:{border:y.arrow.color}}}).filter(function(e){var r=e.webSearchAnswer;return!!(null==r?void 0:r.enhanced_content)})}).map(function(r,n){return e.__assign(e.__assign({},r),{answerOrder:n})})},[o]),h=n.useMemo(function(){return g.reduce(function(e,r){var n,t=(null===(n=r.webSearchAnswer)||void 0===n?void 0:n.extraMetaData)||{};return Object.entries(t).forEach(function(n){var t=n[0],a=n[1],o=p(r.nodeId,r.evaluationKey,t);e[o]={nodeId:r.nodeId,evaluationKey:r.evaluationKey,answerKey:r.answerKey,answerOrder:r.answerOrder,reasoningId:t,evaluation:r.evaluation,webSearchAnswer:r.webSearchAnswer,extraMetaData:a}}),e},{})},[g]),x=n.useMemo(function(){return g.reduce(function(n,t){return n[t.answerKey]={a:function(n){var a=n.href,o=void 0===a?"":a,i=n.children,u=n.type,l=n.reason,s=e.__rest(n,["href","children","type","reason"]),c=null==s?void 0:s["data-cognitive-reasoning"],v=c?p(t.nodeId,t.evaluationKey,String(c)):"",f=v?h[v]:null;return r.jsx(d.default,{href:o,children:i,citationType:u,citationReason:l,metaData:{webGpt:f,webGptMetaKey:v},customStyle:y})}},n},{})},[g,h]);return r.jsx(t.Box,e.__assign({sx:e.__assign(e.__assign({padding:"12px 12px 12px 0px",backgroundColor:"#FFFFFF",borderRadius:"8px"},i.SHARED_MARKDOWN_STYLES),{overflow:"visible"})},{children:g.length>0?g.map(function(n,a){return r.jsx(t.Box,e.__assign({id:n.nodeId===_?"guideline-target-0":void 0,"data-web-gpt-node-id":n.nodeId,"data-web-gpt-evaluation-key":n.evaluationKey,"data-web-gpt-answer-order":n.answerOrder,"data-web-gpt-active":n.nodeId===_?"true":"false",sx:{mb:1.5,border:n.nodeId===_?"2px solid ".concat(n.colorPalette.border):"1px solid #d3d3d3",borderRadius:"6px",padding:"8px",backgroundColor:"#FFFFFF"}},{children:r.jsx(s.default,e.__assign({rehypePlugins:[c.default],components:x[n.answerKey]},{children:n.webSearchAnswer.enhanced_content}))}),n.answerKey)}):r.jsx(t.Typography,e.__assign({sx:{color:"#64748B",fontSize:"14px",py:1}},{children:"No web GPT data available."}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),r=require("react"),a=require("@mui/material"),t=require("react-markdown"),o=require("rehype-raw"),i=require("../../CognitiveCompareConfig.js"),u=require("../../CognitiveComparehelpers.js"),d=require("../../CitationAnchor.js"),l=require("../utils/resolveGuidelineSelection.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=s(t),v=s(o),f=function(e){var n,r,a=e.evalNode;return!1===(null===(r=null===(n=null==a?void 0:a.evaluation_outputs)||void 0===n?void 0:n.guideline_flag)||void 0===r?void 0:r.rulebook_used)},p=function(e,n,r){return"".concat(e,"::").concat(n,"::").concat(r)},y=function(e,n){return"".concat(e,"::").concat(n)},b={relativeWrapper:{verticalAlign:"baseline"},arrow:{color:"#6D28D9"}};exports.default=function(t){var o=t.deviationData,s=t.connectedSections,w=t.proposedSections,g=Array.from(s||[])[0],_=r.useMemo(function(){return l.resolveGuidelineSelection({activeIdentifier:g,deviationData:o,proposedSections:w||[]})},[g,o,w]),h=r.useMemo(function(){if(!o||"object"!=typeof o)return[];return Object.entries(o).flatMap(function(e){var n=e[0];return function(e){var n=e&&"object"==typeof e?e.evaluation_result:null;return!n||"object"!=typeof n&&!Array.isArray(n)?[]:Array.isArray(n)?n.map(function(e,n){return{evalNode:e,evaluationKey:String(n)}}):"object"==typeof n?Object.entries(n).map(function(e){var n=e[0];return{evalNode:e[1],evaluationKey:n}}):[]}(e[1]).filter(f).map(function(e){var r,a,t,o=e.evalNode,i=e.evaluationKey;return{nodeId:n,evaluationKey:i,answerKey:y(n,i),evaluation:o,webSearchAnswer:o.web_search_answer,colorPalette:null!==(t=u.generateColorPalette((null===(a=null===(r=null==o?void 0:o.evaluation_outputs)||void 0===r?void 0:r.metadata)||void 0===a?void 0:a.label_color)||""))&&void 0!==t?t:{border:b.arrow.color}}}).filter(function(e){var n=e.webSearchAnswer;return!!(null==n?void 0:n.enhanced_content)})}).map(function(n,r){return e.__assign(e.__assign({},n),{answerOrder:r})})},[o]),x=r.useMemo(function(){var e;return null===(e=(null==_.evaluationKey?void 0:h.find(function(e){return e.nodeId===_.baseNodeId&&e.evaluationKey===_.evaluationKey}))||h.find(function(e){return e.nodeId===_.baseNodeId}))||void 0===e?void 0:e.answerKey},[_.baseNodeId,_.evaluationKey,h]),K=r.useMemo(function(){return h.reduce(function(e,n){var r,a=(null===(r=n.webSearchAnswer)||void 0===r?void 0:r.extraMetaData)||{};return Object.entries(a).forEach(function(r){var a=r[0],t=r[1],o=p(n.nodeId,n.evaluationKey,a);e[o]={nodeId:n.nodeId,evaluationKey:n.evaluationKey,answerKey:n.answerKey,answerOrder:n.answerOrder,reasoningId:a,evaluation:n.evaluation,webSearchAnswer:n.webSearchAnswer,extraMetaData:t}}),e},{})},[h]),m=r.useMemo(function(){return h.reduce(function(r,a){return r[a.answerKey]={a:function(r){var t=r.href,o=void 0===t?"":t,i=r.children,u=r.type,l=r.reason,s=e.__rest(r,["href","children","type","reason"]),c=null==s?void 0:s["data-cognitive-reasoning"],v=c?p(a.nodeId,a.evaluationKey,String(c)):"",f=v?K[v]:null;return n.jsx(d.default,{href:o,children:i,citationType:u,citationReason:l,metaData:{webGpt:f,webGptMetaKey:v},customStyle:b})}},r},{})},[h,K]);return n.jsx(a.Box,e.__assign({sx:e.__assign(e.__assign({padding:"12px 12px 12px 0px",backgroundColor:"#FFFFFF",borderRadius:"8px"},i.SHARED_MARKDOWN_STYLES),{overflow:"visible"})},{children:h.length>0?h.map(function(r){var t=r.answerKey===x;return n.jsx(a.Box,e.__assign({id:t?"guideline-target-0":void 0,"data-web-gpt-node-id":r.nodeId,"data-web-gpt-evaluation-key":r.evaluationKey,"data-web-gpt-answer-order":r.answerOrder,"data-web-gpt-active":t?"true":"false",sx:{mb:1.5,border:t?"2px solid ".concat(r.colorPalette.border):"1px solid #d3d3d3",borderRadius:"6px",padding:"8px",backgroundColor:"#FFFFFF"}},{children:n.jsx(c.default,e.__assign({rehypePlugins:[v.default],components:m[r.answerKey]},{children:r.webSearchAnswer.enhanced_content}))}),r.answerKey)}):n.jsx(a.Typography,e.__assign({sx:{color:"#64748B",fontSize:"14px",py:1}},{children:"No web GPT data available."}))}))};
2
2
  //# sourceMappingURL=WebGptPanel.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e='[id^="guideline-target-"], [data-web-gpt-active="true"]';exports.GUIDELINE_TARGET_SELECTOR=e,exports.getVisibleGuidelineTargets=function(t){return t?Array.from(t.querySelectorAll(e)).filter(function(e){var t=e.getBoundingClientRect();return t.width>0&&t.height>0}):[]};
2
+ //# sourceMappingURL=guidelineTargets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guidelineTargets.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.processGuidelinesMarkdown=function(t){var a,n,e=t.guidelinesData,o=t.targetHighlights,i=void 0===o?[]:o,r=t.labelColor,l=void 0===r?"#FEF08A":r,c="";if((null==e?void 0:e.learnings_data)&&Object.keys(e.learnings_data).length>0){var u=Object.keys(e.learnings_data)[0],d=e.learnings_data[u];(null==d?void 0:d.instruction_prompt)&&(c=d.instruction_prompt)}else{((null===(n=null===(a=null==e?void 0:e.data)||void 0===a?void 0:a.artifactData)||void 0===n?void 0:n.userStorySnapshot)||[]).forEach(function(t){var a;t.title&&(c+="### ".concat(t.title,"\n\n")),t.value&&(c+="".concat(t.value,"\n\n")),null===(a=t.sub_features)||void 0===a||a.forEach(function(t){t.title&&(c+="#### ".concat(t.title,"\n\n")),t.value&&(c+="".concat(t.value,"\n\n"))})})}return i.forEach(function(t,a){var n=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),e=new RegExp("(".concat(n,")"),"g");c=c.replace(e,'<mark id="guideline-target-'.concat(a,'" style="background-color: ').concat(l,'; border-radius: 3px; padding: 2px;">$1</mark>'))}),c};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=function(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},t=function(n){return n.trim().replace(/\s+/g," ")};exports.processGuidelinesMarkdown=function(r){var a,e,i=r.guidelinesData,o=r.targetHighlights,c=void 0===o?[]:o,l=r.labelColor,u=void 0===l?"#FEF08A":l,s="";return"string"==typeof i?s=i:(null==i?void 0:i.learnings_data)&&"object"==typeof i.learnings_data?(a=i.learnings_data,e=new Set,s=Object.values(a).map(function(n){var r="string"==typeof(null==n?void 0:n.title)?n.title.trim():"",a="string"==typeof(null==n?void 0:n.instruction_prompt)?n.instruction_prompt.trim():"";if(!a)return"";var i="".concat(t(r),"\n").concat(t(a));return e.has(i)?"":(e.add(i),r?"# ".concat(r,"\n\n").concat(a):a)}).filter(Boolean).join("\n\n")):s=function(n){var t,r,a=null===(r=null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.artifactData)||void 0===r?void 0:r.userStorySnapshot;if(!Array.isArray(a))return"";var e="";return a.forEach(function(n){(null==n?void 0:n.title)&&(e+="### ".concat(n.title,"\n\n")),(null==n?void 0:n.value)&&(e+="".concat(n.value,"\n\n")),Array.isArray(null==n?void 0:n.sub_features)&&n.sub_features.forEach(function(n){(null==n?void 0:n.title)&&(e+="#### ".concat(n.title,"\n\n")),(null==n?void 0:n.value)&&(e+="".concat(n.value,"\n\n"))})}),e.trim()}(i),function(r,a,e){var i=r,o=new Set,c=0;return a.forEach(function(r){if("string"==typeof r){var a=r.trim(),l=t(a).toLocaleLowerCase();if(l&&!o.has(l)){o.add(l);var u=a.split(/\s+/).map(n).join("\\s+"),s=new RegExp(u,"i").exec(i);if(s){var d='<mark id="guideline-target-'.concat(c,'" style="background-color: ').concat(e,'; border-radius: 3px; padding: 2px;">').concat(s[0],"</mark>");i="".concat(i.slice(0,s.index)).concat(d).concat(i.slice(s.index+s[0].length)),c+=1}}}}),i}(s,Array.isArray(c)?c:[],u||"#FEF08A")};
2
2
  //# sourceMappingURL=processGuidelinesMarkdown.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../CognitiveComparehelpers.js");exports.resolveGuidelineSelection=function(i){var o,l=i.activeIdentifier,r=i.deviationData,t=i.proposedSections,a="",n=null;if("number"==typeof l){var u=t[l],v=(null==u?void 0:u.nodeId)||(null==u?void 0:u.id);a="string"==typeof v?v:""}else if("string"==typeof l){var d=l.split(e.DEVIATION_BADGE_SEPARATOR);a=d[0]||"",n=d.length>1&&""!==d[1]?d[1]:null}var s=null===(o=null==r?void 0:r[a])||void 0===o?void 0:o.evaluation_result;if(!s||"object"!=typeof s)return{baseNodeId:a,evaluationKey:n,evaluationNodes:[],targetHighlights:[],labelColor:""};var f=null==n?void 0:function(e,i){if(Array.isArray(e)){var o=Number(i);return Number.isInteger(o)?e[o]:void 0}return null==e?void 0:e[i]}(s,n),g=null==n?Object.values(s):f?[f]:[],p=new Set,c=[],h="";return g.forEach(function(e){var i,o,l,r=null===(i=null==e?void 0:e.deviation_highlights)||void 0===i?void 0:i.rulebook_guidelines;if(Array.isArray(r)&&r.forEach(function(e){if("string"==typeof e&&e.trim()){var i=e.trim().replace(/\s+/g," ").toLocaleLowerCase();p.has(i)||(p.add(i),c.push(e))}}),!h){var t=null===(l=null===(o=null==e?void 0:e.evaluation_outputs)||void 0===o?void 0:o.metadata)||void 0===l?void 0:l.label_color;"string"==typeof t&&(h=t)}}),{baseNodeId:a,evaluationKey:n,evaluationNodes:g,targetHighlights:c,labelColor:h}};
2
+ //# sourceMappingURL=resolveGuidelineSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveGuidelineSelection.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("tslib"),e=require("react"),t=require("../CognitiveComparehelpers.js"),i=require("../utils/buildComparisonRows.js"),o={id:"",title:"",similarity:0,sections:[]};exports.useCognitiveTreeData=function(r,a,s,d,l,u){var v,c;void 0===l&&(l=!0);var f="string"==typeof s?s:JSON.stringify(s||{}),p=Boolean(u&&(u.learnings_data||(null===(c=null===(v=u.data)||void 0===v?void 0:v.artifactData)||void 0===c?void 0:c.userStorySnapshot))),_=e.useMemo(function(){if(!r||0===Object.keys(r).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var e=JSON.parse(f);try{var o=r.nodes||r,s=[],d=[],v=[],c=r.base_root_id,_=r.input_index_map||{0:"left",1:"right"},I=r[c]||o[c];if(!I||!1===I.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var g=r.content_mapping||{},h=function(n){return r[n]||o[n]},m=function(e,i,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(l)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),s={},d={},u=null;return a.forEach(function(n){var r,a,l,v,c,f,p=e[n];if(p&&"object"==typeof p){u||(u=p);var I=!(null==p?void 0:p.status)||"pending"===p.status,g=(null==p?void 0:p.deviation_highlight)||(null===(a=null==p?void 0:p.web_search_answer)||void 0===a?void 0:a.deviation_highlight),h=function(n){var e,t=(null===(e=null==p?void 0:p.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==p?void 0:p.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},m=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var i=0,o=n;i<o.length;i++){var r=o[i];if(Array.isArray(r)&&r.some(function(n){return!t.isMissingStr(n)}))return r}return[]},y=I?m((null===(l=null==p?void 0:p.deviation_highlights)||void 0===l?void 0:l[i])||(null===(v=null==p?void 0:p.deviation_highlights)||void 0===v?void 0:v[_[0]]),"string"==typeof g?[g]:[],h(i),h(_[0])):[],b=I?m((null===(c=null==p?void 0:p.deviation_highlights)||void 0===c?void 0:c[o])||(null===(f=null==p?void 0:p.deviation_highlights)||void 0===f?void 0:f[_[1]]),h(o),h(_[1])):[];s[n]=((r={})[_[0]]=y[0]||"",r[_[1]]=b[0]||"",r.deviation_summary=(null==p?void 0:p.deviation_summary)||"",r.deviation_title=null==p?void 0:p.deviation_title,r.deviation_impact=null==p?void 0:p.deviation_impact,r.deviation_explanation=null==p?void 0:p.deviation_explanation,r.evaluation_outputs=null==p?void 0:p.evaluation_outputs,r.cognitive_decisioning=null==p?void 0:p.cognitive_decisioning,r.deviation_highlights=null==p?void 0:p.deviation_highlights,r),d[n]=p}}),n.__assign(n.__assign({},e),{deviation_title:(null==u?void 0:u.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==u?void 0:u.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==u?void 0:u.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==u?void 0:u.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==u?void 0:u.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==u?void 0:u.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:s,deviation_entries:d})},y=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var s=e.get(a);s.subsections||(s.subsections=[]),s.subsections.some(function(e){return e.id===n.id})||s.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},s=0,d=n;s<d.length;s++){a(d[s])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},b=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=_[0],i=_[1];return e.length>0&&(t=e.includes(_[0])?_[0]:e[0],i=e.includes(_[1])?_[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},x=function(e,i,o,r){var a=i.attributes||{},s=i.data||{},d=!1!==a.display_title,l=!1!==a.display_content,u=d?t.safeStringify(s.title||""):"",v=l?t.safeStringify(s.content||""):"",c=l?t.safeStringify(s.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),_=!(!u.trim()&&!v.trim());return n.__assign(n.__assign({id:"".concat(e,"::").concat(i.contentId),nodeId:e,contentId:i.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:d,displayContent:l,subsections:[]},_?r:{score:void 0,relation:"not_defined"}),{evaluationResult:o,evaluationResults:o?[o]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},R=function(e,t){e.refIndexes=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refIndexes||[],!0),t.refIndexes||[],!0))),e.refContentIds=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((e.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(e.subsections=n.__spreadArray(n.__spreadArray([],e.subsections||[],!0),[t],!1),i.add(o))});var o=n.__spreadArray(n.__spreadArray([],e.evaluationResults||(e.evaluationResult?[e.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return e.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!e.evaluationResult&&t.evaluationResult&&(e.evaluationResult=t.evaluationResult),!e.cognitiveData&&t.cognitiveData&&(e.cognitiveData=t.cognitiveData),e},C=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},S=function(i,o){var r,a=h(i);if(!a||!1===a.display_node)return[];if(p&&"1"===o)return[];var s=b(a),d=s.nodeLeftId,l=s.nodeRightId,u=t.getRationale(a),v=(null===(r=null==e?void 0:e[i])||void 0===r?void 0:r.evaluation_result)||a.evaluation_result||null,c=m(v,d,l),f=c&&"object"==typeof c?n.__assign(n.__assign({},c),{nodeId:i}):c,I=t.resolveComparisonInputItems(a,o,_,g).map(function(n){return x(i,n,f,u)});if(a.next){var y=Object.values(a.next).flatMap(function(n){return S(n,o)});I.forEach(function(n){var e=y.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:y})}return I};if(a){var E=function(i,o){var r;void 0===o&&(o=0);var a=[],s=[];if(!i)return{refSections:a,baseSections:s};var d={},l={},u=-1,v=-1,c=function(a){var s=i[a],c=h(s);if(!c||!1===c.display_node)return"continue";var f=b(c),I=f.nodeLeftId,y=f.nodeRightId,C=t.getRationale(c),S=(null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.evaluation_result)||c.evaluation_result||null,O=m(S,I,y),j=O&&"object"==typeof O?n.__assign(n.__assign({},O),{nodeId:s}):O,N=E(c.next,o+1),w=N.refSections,A=N.baseSections,D=t.resolveComparisonInputItems(c,"0",_,g).map(function(n){var e=x(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=v--),e}),k=[];if(!p){var M=t.resolveComparisonInputItems(c,"1",_,g);k=M.map(function(n){var e=x(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=u--),e})}D.forEach(function(n){k.forEach(function(e){var t,i,o,r,a,s,d,l;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(s=e.refContentIds)||void 0===s||s.push(n.contentId)),e.contentId&&!(null===(d=n.refContentIds)||void 0===d?void 0:d.includes(e.contentId))&&(null===(l=n.refContentIds)||void 0===l||l.push(e.contentId))})}),k.forEach(function(n){var e=w.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);d[t]=d[t]?R(d[t],n):n}),D.forEach(function(n){var e=A.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);l[t]=l[t]?R(l[t],n):n})};for(var f in i)c(f);return a=Object.values(d),s=Object.values(l),a.sort(C),s.sort(C),{refSections:a,baseSections:s}},O=E(I.next),j=O.refSections,N=O.baseSections;p||(d=y(j)),s=N}else I.next&&Object.values(I.next).forEach(function(n){var e=h(n);if(e&&!1!==e.display_node){var t=S(n,"0");if(p)s.push.apply(s,t);else{var o=y(S(n,"1"));v.push.apply(v,i.buildComparisonRows(n,t,o))}}}),p||(s=v.map(function(n){return n.left}),d=v.map(function(n){return n.right}));var w=t.getSideData(I,"0",_,g),A=t.getSideData(I,"1",_,g),D={title:w.title||"Uploaded Contract",description:I.decision_scope_description||"",sections:s},k={id:"tree-variant-1",title:p?function(){var n,e;if((null==u?void 0:u.learnings_data)&&Object.keys(u.learnings_data).length>0){var t=Object.keys(u.learnings_data)[0];return(null===(n=u.learnings_data[t])||void 0===n?void 0:n.title)||"Rulebook Guidelines"}return(null===(e=null==u?void 0:u.data)||void 0===e?void 0:e.artifactTitle)||"Rulebook Guidelines"}():A.title||"Reference Template",similarity:0,sections:d,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:I.decision_scope_description||""},fields:{}}}};return{activeProposed:D,activeVariants:[k],comparisonRows:v,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[r,a,f,l,u]),I=_.activeProposed,g=_.activeVariants,h=_.comparisonRows,m=_.parseError,y=(null==g?void 0:g[0])||o,b=e.useMemo(function(){return(null==I?void 0:I.sections)||[]},[null==I?void 0:I.sections]),x=e.useMemo(function(){return y.sections||[]},[y.sections]),R=b.length>0||x.length>0,C=e.useMemo(function(){return d.fields.filter(function(n){var e=n.key;return(!R||"description"!==e)&&(t.hasValue(null==I?void 0:I[e])||t.hasValue(y[e]))})},[I,y,R,d.fields]),S=e.useMemo(function(){var n,e,i={},o={},s={},d=0,l=null===(n=null==r?void 0:r.input_index_map)||void 0===n?void 0:n[0],u=null===(e=null==r?void 0:r.input_index_map)||void 0===e?void 0:e[1],v=function(n,e){if(!a){var t="left"===e?b.indexOf(n):x.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:b.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,s=b.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(s){var d=s.selfIndex,l=void 0!==d&&d>=0?d+1:b.indexOf(s)+1;return{rootKey:"left-root:".concat(s.id),parentNum:l}}var u=void 0!==r&&r>=0?r+1:x.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:u}},c=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},f=function(n,e,r,a,v,p,_){if(e&&function(n,e,i){var r;((null===(r=null==n?void 0:n.evaluationResults)||void 0===r?void 0:r.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(r){var a=(null==r?void 0:r.deviations)||{};Object.keys(a).sort().forEach(function(d){var v=a[d];if(v){var c=!t.isMissingStr(v[l]),f=!t.isMissingStr(v[u]);if(c||f){var p=(null==r?void 0:r.nodeId)||n.nodeId||n.id,_="".concat(p).concat(t.DEVIATION_BADGE_SEPARATOR).concat(d);void 0===o[_]&&(void 0===s[e]&&(s[e]=1),o[_]={index:s[e]++,rootKey:e,parentNum:i})}}})})}(e,a,v),e&&!p){var I=(null==_?void 0:_.id)||"fallback_parent_".concat(d++);i[I]||(i[I]=[]),i[I].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==r?void 0:r.subsections)||[]).forEach(function(t){var i=c(null==n?void 0:n.subsections,t),o=c(null==r?void 0:r.subsections,t);f(t,i,o,a,v,!1,e||_)})};b.forEach(function(n){var e,t=v(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(a){var s=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=x.find(function(n){return n.selfIndex===s})}else r=x[b.indexOf(n)];f(n,n,r,i,o,!0,n)}),p||x.forEach(function(n){var e=v(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&f(n,null,n,t,i,!0,n)});var _=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),I=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:i,registry:_,deviationParentRegistry:I}},[b,x,a,r,p]),E=S.parentDeviationRecord,O=S.registry,j=S.deviationParentRegistry;return{isGuidelineMode:p,activeProposed:I,activeVariants:g,comparisonRows:h,existingRule:y,proposedSections:b,existingSections:x,visibleFields:C,parentDeviationRecord:E,deviationNumberRegistry:O,deviationParentRegistry:j,parseError:m}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("tslib"),e=require("react"),t=require("../CognitiveComparehelpers.js"),i=require("../utils/buildComparisonRows.js"),o={id:"",title:"",similarity:0,sections:[]};exports.useCognitiveTreeData=function(r,a,s,l,d,u,v){var c,f;void 0===d&&(d=!0);var p="string"==typeof s?s:JSON.stringify(s||{}),_=null!=v?v:Boolean("string"==typeof u?u.trim():u&&(u.learnings_data||(null===(f=null===(c=u.data)||void 0===c?void 0:c.artifactData)||void 0===f?void 0:f.userStorySnapshot))),g=e.useMemo(function(){if(!r||0===Object.keys(r).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var e=JSON.parse(p);try{var o=r.nodes||r,s=[],l=[],v=[],c=r.base_root_id,f=r.input_index_map||{0:"left",1:"right"},g=r[c]||o[c];if(!g||!1===g.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var I=r.content_mapping||{},h=function(n){return r[n]||o[n]},m=function(e,i,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(d)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),s={},l={},u=null;return a.forEach(function(n){var r,a,d,v,c,p,_=e[n];if(_&&"object"==typeof _){u||(u=_);var g=!(null==_?void 0:_.status)||"pending"===_.status,I=(null==_?void 0:_.deviation_highlight)||(null===(a=null==_?void 0:_.web_search_answer)||void 0===a?void 0:a.deviation_highlight),h=function(n){var e,t=(null===(e=null==_?void 0:_.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==_?void 0:_.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},m=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var i=0,o=n;i<o.length;i++){var r=o[i];if(Array.isArray(r)&&r.some(function(n){return!t.isMissingStr(n)}))return r}return[]},y=g?m((null===(d=null==_?void 0:_.deviation_highlights)||void 0===d?void 0:d[i])||(null===(v=null==_?void 0:_.deviation_highlights)||void 0===v?void 0:v[f[0]]),"string"==typeof I?[I]:[],h(i),h(f[0])):[],b=g?m((null===(c=null==_?void 0:_.deviation_highlights)||void 0===c?void 0:c[o])||(null===(p=null==_?void 0:_.deviation_highlights)||void 0===p?void 0:p[f[1]]),h(o),h(f[1])):[];s[n]=((r={})[f[0]]=y[0]||"",r[f[1]]=b[0]||"",r.deviation_summary=(null==_?void 0:_.deviation_summary)||"",r.deviation_title=null==_?void 0:_.deviation_title,r.deviation_impact=null==_?void 0:_.deviation_impact,r.deviation_explanation=null==_?void 0:_.deviation_explanation,r.evaluation_outputs=null==_?void 0:_.evaluation_outputs,r.cognitive_decisioning=null==_?void 0:_.cognitive_decisioning,r.deviation_highlights=null==_?void 0:_.deviation_highlights,r),l[n]=_}}),n.__assign(n.__assign({},e),{deviation_title:(null==u?void 0:u.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==u?void 0:u.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==u?void 0:u.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==u?void 0:u.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==u?void 0:u.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==u?void 0:u.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:s,deviation_entries:l})},y=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var s=e.get(a);s.subsections||(s.subsections=[]),s.subsections.some(function(e){return e.id===n.id})||s.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},s=0,l=n;s<l.length;s++){a(l[s])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},b=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=f[0],i=f[1];return e.length>0&&(t=e.includes(f[0])?f[0]:e[0],i=e.includes(f[1])?f[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},x=function(e,i,o,r){var a=i.attributes||{},s=i.data||{},l=!1!==a.display_title,d=!1!==a.display_content,u=l?t.safeStringify(s.title||""):"",v=d?t.safeStringify(s.content||""):"",c=d?t.safeStringify(s.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),_=!(!u.trim()&&!v.trim());return n.__assign(n.__assign({id:"".concat(e,"::").concat(i.contentId),nodeId:e,contentId:i.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:l,displayContent:d,subsections:[]},_?r:{score:void 0,relation:"not_defined"}),{evaluationResult:o,evaluationResults:o?[o]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},R=function(e,t){e.refIndexes=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refIndexes||[],!0),t.refIndexes||[],!0))),e.refContentIds=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((e.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(e.subsections=n.__spreadArray(n.__spreadArray([],e.subsections||[],!0),[t],!1),i.add(o))});var o=n.__spreadArray(n.__spreadArray([],e.evaluationResults||(e.evaluationResult?[e.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return e.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!e.evaluationResult&&t.evaluationResult&&(e.evaluationResult=t.evaluationResult),!e.cognitiveData&&t.cognitiveData&&(e.cognitiveData=t.cognitiveData),e},C=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},S=function(i,o){var r,a=h(i);if(!a||!1===a.display_node)return[];if(_&&"1"===o)return[];var s=b(a),l=s.nodeLeftId,d=s.nodeRightId,u=t.getRationale(a),v=(null===(r=null==e?void 0:e[i])||void 0===r?void 0:r.evaluation_result)||a.evaluation_result||null,c=m(v,l,d),p=c&&"object"==typeof c?n.__assign(n.__assign({},c),{nodeId:i}):c,g=t.resolveComparisonInputItems(a,o,f,I).map(function(n){return x(i,n,p,u)});if(a.next){var y=Object.values(a.next).flatMap(function(n){return S(n,o)});g.forEach(function(n){var e=y.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:y})}return g};if(a){var E=function(i,o){var r;void 0===o&&(o=0);var a=[],s=[];if(!i)return{refSections:a,baseSections:s};var l={},d={},u=-1,v=-1,c=function(a){var s=i[a],c=h(s);if(!c||!1===c.display_node)return"continue";var p=b(c),g=p.nodeLeftId,y=p.nodeRightId,C=t.getRationale(c),S=(null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.evaluation_result)||c.evaluation_result||null,O=m(S,g,y),j=O&&"object"==typeof O?n.__assign(n.__assign({},O),{nodeId:s}):O,N=E(c.next,o+1),w=N.refSections,A=N.baseSections,D=t.resolveComparisonInputItems(c,"0",f,I).map(function(n){var e=x(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=v--),e}),k=[];if(!_){var M=t.resolveComparisonInputItems(c,"1",f,I);k=M.map(function(n){var e=x(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=u--),e})}D.forEach(function(n){k.forEach(function(e){var t,i,o,r,a,s,l,d;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(s=e.refContentIds)||void 0===s||s.push(n.contentId)),e.contentId&&!(null===(l=n.refContentIds)||void 0===l?void 0:l.includes(e.contentId))&&(null===(d=n.refContentIds)||void 0===d||d.push(e.contentId))})}),k.forEach(function(n){var e=w.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);l[t]=l[t]?R(l[t],n):n}),D.forEach(function(n){var e=A.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);d[t]=d[t]?R(d[t],n):n})};for(var p in i)c(p);return a=Object.values(l),s=Object.values(d),a.sort(C),s.sort(C),{refSections:a,baseSections:s}},O=E(g.next),j=O.refSections,N=O.baseSections;_||(l=y(j)),s=N}else g.next&&Object.values(g.next).forEach(function(n){var e=h(n);if(e&&!1!==e.display_node){var t=S(n,"0");if(_)s.push.apply(s,t);else{var o=y(S(n,"1"));v.push.apply(v,i.buildComparisonRows(n,t,o))}}}),_||(s=v.map(function(n){return n.left}),l=v.map(function(n){return n.right}));var w=t.getSideData(g,"0",f,I),A=t.getSideData(g,"1",f,I),D={title:w.title||"Uploaded Contract",description:g.decision_scope_description||"",sections:s},k={id:"tree-variant-1",title:_?function(){var n,e;if("string"!=typeof u&&(null==u?void 0:u.learnings_data)&&Object.keys(u.learnings_data).length>0){var t=Object.keys(u.learnings_data)[0];return(null===(n=u.learnings_data[t])||void 0===n?void 0:n.title)||"Rulebook Guidelines"}return"string"!=typeof u&&(null===(e=null==u?void 0:u.data)||void 0===e?void 0:e.artifactTitle)||"Rulebook Guidelines"}():A.title||"Reference Template",similarity:0,sections:l,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:g.decision_scope_description||""},fields:{}}}};return{activeProposed:D,activeVariants:[k],comparisonRows:v,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[r,a,p,d,u,_]),I=g.activeProposed,h=g.activeVariants,m=g.comparisonRows,y=g.parseError,b=(null==h?void 0:h[0])||o,x=e.useMemo(function(){return(null==I?void 0:I.sections)||[]},[null==I?void 0:I.sections]),R=e.useMemo(function(){return b.sections||[]},[b.sections]),C=x.length>0||R.length>0,S=e.useMemo(function(){return l.fields.filter(function(n){var e=n.key;return(!C||"description"!==e)&&(t.hasValue(null==I?void 0:I[e])||t.hasValue(b[e]))})},[I,b,C,l.fields]),E=e.useMemo(function(){var n,e,i={},o={},s={},l=0,d=null===(n=null==r?void 0:r.input_index_map)||void 0===n?void 0:n[0],u=null===(e=null==r?void 0:r.input_index_map)||void 0===e?void 0:e[1],v=function(n,e){if(!a){var t="left"===e?x.indexOf(n):R.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:x.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,s=x.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(s){var l=s.selfIndex,d=void 0!==l&&l>=0?l+1:x.indexOf(s)+1;return{rootKey:"left-root:".concat(s.id),parentNum:d}}var u=void 0!==r&&r>=0?r+1:R.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:u}},c=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},f=function(n,e,r,a,v,p,_){if(e&&function(n,e,i){var r;((null===(r=null==n?void 0:n.evaluationResults)||void 0===r?void 0:r.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(r){var a=(null==r?void 0:r.deviations)||{};Object.keys(a).sort().forEach(function(l){var v=a[l];if(v){var c=!t.isMissingStr(v[d]),f=!t.isMissingStr(v[u]);if(c||f){var p=(null==r?void 0:r.nodeId)||n.nodeId||n.id,_="".concat(p).concat(t.DEVIATION_BADGE_SEPARATOR).concat(l);void 0===o[_]&&(void 0===s[e]&&(s[e]=1),o[_]={index:s[e]++,rootKey:e,parentNum:i})}}})})}(e,a,v),e&&!p){var g=(null==_?void 0:_.id)||"fallback_parent_".concat(l++);i[g]||(i[g]=[]),i[g].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==r?void 0:r.subsections)||[]).forEach(function(t){var i=c(null==n?void 0:n.subsections,t),o=c(null==r?void 0:r.subsections,t);f(t,i,o,a,v,!1,e||_)})};x.forEach(function(n){var e,t=v(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(a){var s=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=R.find(function(n){return n.selfIndex===s})}else r=R[x.indexOf(n)];f(n,n,r,i,o,!0,n)}),_||R.forEach(function(n){var e=v(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&f(n,null,n,t,i,!0,n)});var p=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),g=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:i,registry:p,deviationParentRegistry:g}},[x,R,a,r,_]),O=E.parentDeviationRecord,j=E.registry,N=E.deviationParentRegistry;return{isGuidelineMode:_,activeProposed:I,activeVariants:h,comparisonRows:m,existingRule:b,proposedSections:x,existingSections:R,visibleFields:S,parentDeviationRecord:O,deviationNumberRegistry:j,deviationParentRegistry:N,parseError:y}};
2
2
  //# sourceMappingURL=useCompareData.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../CognitiveComparehelpers.js");exports.useLinesCalculator=function(n){var i=n.containerRef,r=n.leftContainerRef,c=n.rightContainerRef;n.svgContainerRef;var l=n.pathRefs,o=n.leftHeaderRef,u=n.rightHeaderRef,a=n.proposedSections,d=n.existingSections,s=n.visibleFields,v=n.leftRefs,h=n.rightRefs,g=n.sectionLeftRefs,f=n.sectionRightRefs,p=n.subSectionLeftRefs,b=n.subSectionRightRefs,A=n.lhsBadgeRefs,y=n.rhsBadgeRefs,R=n.sectionRowRefs,x=n.expandedSections,m=n.expandedSubSections,B=n.connectedSections,S=n.isSideBySide,I=n.activeSideBySideSection,T=n.maintainRelativeOrder,C=n.isGuidelineMode,E=n.cognitiveMap,M=n.getSectionCompareStyle,D=n.getSubSectionCompareStyle,O=n.getDeviationStyleByKey,L=n.isArrowVisible,_=n.isAnimatingRef,F=n.isSideBySideRef,N=n.sideBySideCacheRef,H=n.sideBySideLineRef,P=n.activeSideBySideSectionRef,k=n.activeSideBySideRightSectionRef,w=n.connectedLines,G=n.setConnectedLines,V=n.cachedConnectedPositions,Y=n.calculateLinesRef,j=n.resizeTimerRef,z=n.scrollLock,Q=n.scrollSyncLocked,X=n.handleResizeRef,q=n.activeProposed,K=n.existingRule,J=n.analysisData,U=n.pendingScrollTargetRef,W=n.pendingScrollCallbackRef,Z=n.resolvedComparisonConfig,$=n.getFieldData,tt=t.useState([]),et=tt[0],nt=tt[1],it=t.useState(null),rt=it[0],ct=it[1],lt=t.useState([]),ot=lt[0],ut=lt[1],at=null!=w?w:ot,dt=null!=G?G:ut,st=t.useState({width:0,height:0}),vt=st[0],ht=st[1],gt=t.useRef(!1),ft=t.useRef(!1),pt=t.useRef(!1),bt=t.useRef(null),At=t.useRef([]),yt=null!=V?V:At,Rt=function(t,e,n,i,r,c,l){if(Math.abs(i-e)<=1)return c&&l?"M ".concat(t,",").concat(e," L ").concat(n,",").concat(i):c&&!l?"M ".concat(t,",").concat(e," L ").concat(r,",").concat(e):!c&&l?"M ".concat(r,",").concat(e," L ").concat(n,",").concat(i):"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i);var o=Math.min(15,Math.abs(r-t),Math.abs(i-e)/2),u=Math.min(15,Math.abs(n-r),Math.abs(i-e)/2),a=i>e?o:-o,d=i>e?u:-u,s=n>r?u:-u;return c&&l?"M ".concat(t,",").concat(e," L ").concat(r-o,",").concat(e," Q ").concat(r,",").concat(e," ").concat(r,",").concat(e+a," L ").concat(r,",").concat(i-d," Q ").concat(r,",").concat(i," ").concat(r+s,",").concat(i," L ").concat(n,",").concat(i):c&&!l?"M ".concat(t,",").concat(e," L ").concat(r-o,",").concat(e," Q ").concat(r,",").concat(e," ").concat(r,",").concat(e+a," L ").concat(r,",").concat(i):!c&&l?"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i-d," Q ").concat(r,",").concat(i," ").concat(r+s,",").concat(i," L ").concat(n,",").concat(i):"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i)},xt=t.useCallback(function(){var t,n,l,R,L,F,N,H,P,k,w,G,V,Y,j,z,Q,X;if(!gt.current&&!_.current){gt.current=!0;try{if(!i.current)return;var q=function(t){var e=t.split("-"),n=e[0];if(!x[n]&&!1===T)return!1;if(T&&!x["left-".concat(n)]&&!x["right-".concat(n)]&&!x[n])return!1;for(var i=n,r=1;r<e.length-1;r++)if(i+="-".concat(e[r]),!m[i])return!1;return!0},K=i.current.getBoundingClientRect();ht({width:K.width,height:K.height});var J=[];if(s.forEach(function(t){var e,n,i=t.key,r=null===(e=v.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;r&&c&&(r.style.height="auto",c.style.height="auto",r.style.minHeight="0px",c.style.minHeight="0px")}),!_.current){for(var U=0;U<Math.max(a.length,d.length);U++){var W=null===(t=g.current[U])||void 0===t?void 0:t.current,Z=null===(n=f.current[U])||void 0===n?void 0:n.current;W&&(W.style.height="auto",W.style.minHeight="0px"),Z&&(Z.style.height="auto",Z.style.minHeight="0px")}T||Object.keys(p.current).forEach(function(t){var e,n;if(q(t)){var i=null===(e=p.current[t])||void 0===e?void 0:e.current,r=null===(n=b.current[t])||void 0===n?void 0:n.current;i&&r&&(i.style.height="auto",r.style.height="auto",i.style.minHeight="0px",r.style.minHeight="0px")}})}var $={};s.forEach(function(t){var e,n,i=t.key,r=null===(e=v.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;if(r&&c){var l=r.getBoundingClientRect(),o=c.getBoundingClientRect();$[i]=Math.max(l.height,o.height)}});var tt={left:{},right:{}},et={};if(!_.current)if(T){if(S&&null!==I)if("number"==typeof I){var it=I,rt=a[it],lt=null===(L=g.current[it])||void 0===L?void 0:L.current;lt&&rt&&(rt.refIndexes||[]).forEach(function(t){var e,n=d.findIndex(function(e){return e.selfIndex===t}),i=null===(e=f.current[n])||void 0===e?void 0:e.current;if(i&&(x["left-".concat(it)]||x["right-".concat(n)])){var r=Math.max(lt.getBoundingClientRect().height,i.getBoundingClientRect().height);tt.left[it]=Math.max(tt.left[it]||0,r),tt.right[n]=Math.max(tt.right[n]||0,r)}})}else{var ot=I.split(e.DEVIATION_BADGE_SEPARATOR)[2];if(ot){W=null===(F=p.current[ot])||void 0===F?void 0:F.current,Z=null===(N=b.current[ot])||void 0===N?void 0:N.current;if(W&&Z){ut=Math.max(W.getBoundingClientRect().height,Z.getBoundingClientRect().height);et[ot]=Math.max(et[ot]||0,ut)}}}}else{Object.keys(p.current).forEach(function(t){var e,n;if(q(t)){var i=null===(e=p.current[t])||void 0===e?void 0:e.current,r=null===(n=b.current[t])||void 0===n?void 0:n.current;if(i&&r&&null!==i.offsetParent&&null!==r.offsetParent){var c=i.getBoundingClientRect(),l=r.getBoundingClientRect(),o=Math.max(c.height,l.height);et[t]=o,i.style.minHeight="".concat(o,"px"),r.style.minHeight="".concat(o,"px")}}});for(U=0;U<Math.min(a.length,d.length);U++){var W=null===(l=g.current[U])||void 0===l?void 0:l.current,Z=null===(R=f.current[U])||void 0===R?void 0:R.current;if(W&&Z){var ut=Math.max(W.getBoundingClientRect().height,Z.getBoundingClientRect().height);tt.left[U]=ut,tt.right[U]=ut}}}if(s.forEach(function(t){var e,n,i=t.key,r=null===(e=v.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;if(r&&c){var l=$[i];r.style.minHeight="".concat(l,"px"),c.style.minHeight="".concat(l,"px")}}),_.current||(Object.entries(tt.left).forEach(function(t){var e,n=t[0],i=t[1],r=null===(e=g.current[Number(n)])||void 0===e?void 0:e.current;r&&(r.style.minHeight="".concat(i,"px"))}),Object.entries(tt.right).forEach(function(t){var e,n=t[0],i=t[1],r=null===(e=f.current[Number(n)])||void 0===e?void 0:e.current;r&&(r.style.minHeight="".concat(i,"px"))}),T||Object.keys(et).forEach(function(t){var e,n,i=null===(e=p.current[t])||void 0===e?void 0:e.current,r=null===(n=b.current[t])||void 0===n?void 0:n.current;if(i&&r&&et[t]){var c=et[t];i.style.minHeight="".concat(c,"px"),r.style.minHeight="".concat(c,"px")}})),!C){a.forEach(function(t,e){var n,i=t.continuationSourceRowId?a.findIndex(function(e){return e.comparisonRowId===t.continuationSourceRowId}):-1,l=i>=0?i:e,o=null===(n=g.current[l])||void 0===n?void 0:n.current;if(o){var u=function(t,e){if(!T)return d[e]?[e]:[];var n=(t.refIndexes||[]).map(function(t){return d.findIndex(function(e){return e.selfIndex===t})}).filter(function(t){return-1!==t});return!n.length&&d[e]?[e]:Array.from(new Set(n))}(t,e);u.forEach(function(t){var n,u,s,v,h,g,p,b,A,y,R,x,m=null===(n=f.current[t])||void 0===n?void 0:n.current;if(m){var B=o.getBoundingClientRect(),C=m.getBoundingClientRect(),D=B.right-K.left,O=C.left-K.left,L=B.top+18-K.top,_=C.top+18-K.top;if(T&&S&&I===e){var F=null!==(s=null===(u=r.current)||void 0===u?void 0:u.getBoundingClientRect().top)&&void 0!==s?s:0,N=null!==(h=null===(v=c.current)||void 0===v?void 0:v.getBoundingClientRect().top)&&void 0!==h?h:0,H=F+(null!==(p=null===(g=r.current)||void 0===g?void 0:g.clientHeight)&&void 0!==p?p:1/0),P=N+(null!==(A=null===(b=c.current)||void 0===b?void 0:b.clientHeight)&&void 0!==A?A:1/0),k=function(t,e,n){return Math.max(e,Math.min(n,t))};L=k(B.top+18,F,H)-K.top,_=k(C.top+18,N,P)-K.top}var w=M(l);w&&J.push({id:"line-".concat(l,"-").concat(t),x1:D,y1:L,x2:O,y2:_,style:w,sectionIdx:l,targetRightIdx:t,isSubSection:!1,isMappingContinuation:i>=0,hasCognitive:!!((null===(y=a[l])||void 0===y?void 0:y.cognitiveData)||(null===(R=d[t])||void 0===R?void 0:R.cognitiveData)||(null===(x=a[l])||void 0===x?void 0:x.nodeId)&&E[a[l].nodeId])})}})}})}if(!C&&S&&"string"==typeof I&&I.includes(e.DEVIATION_BADGE_SEPARATOR)){var at=I.split(e.DEVIATION_BADGE_SEPARATOR),st=at[0],vt=at[1],ft=at[2],pt=(at[3],"".concat(st).concat(e.DEVIATION_BADGE_SEPARATOR).concat(vt)),bt=null===(H=A.current[pt])||void 0===H?void 0:H.current,At=null===(P=y.current[pt])||void 0===P?void 0:P.current;if(bt&&At){var xt=bt.getBoundingClientRect(),Bt=At.getBoundingClientRect(),St=xt.right-K.left,It=Bt.left-K.left,Tt=xt.top+xt.height/2-K.top,Ct=Bt.top+Bt.height/2-K.top;if(T){var Et=null!==(w=null===(k=r.current)||void 0===k?void 0:k.getBoundingClientRect().top)&&void 0!==w?w:0,Mt=null!==(V=null===(G=c.current)||void 0===G?void 0:G.getBoundingClientRect().top)&&void 0!==V?V:0,Dt=Et+(null!==(j=null===(Y=r.current)||void 0===Y?void 0:Y.clientHeight)&&void 0!==j?j:1/0),Ot=Mt+(null!==(Q=null===(z=c.current)||void 0===z?void 0:z.clientHeight)&&void 0!==Q?Q:1/0),Lt=function(t,e,n){return Math.max(e,Math.min(n,t))};Tt=Lt(xt.top+xt.height/2,Et,Dt)-K.top,Ct=Lt(Bt.top+Bt.height/2,Mt,Ot)-K.top}var _t=null!==(X=O(st,vt))&&void 0!==X?X:D(ft);_t&&J.push({id:"line-subsec-".concat(pt),x1:St,y1:Tt,x2:It,y2:Ct,style:_t,sectionIdx:Number(ft.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(nt(J),o.current&&u.current){var Ft=o.current.getBoundingClientRect(),Nt=u.current.getBoundingClientRect(),Ht=(Ft.top+Ft.height/2-K.top+Nt.top+Nt.height/2-K.top)/2;ct({x1:Ft.right-K.left,x2:Nt.left-K.left,y:Ht})}else ct(null);if(B.size>0){var Pt=[],kt=r.current,wt=c.current;if(kt&&wt){var Gt=[],Vt=kt.getBoundingClientRect().top,Yt=wt.getBoundingClientRect().top,jt=Vt+kt.clientHeight,zt=Yt+wt.clientHeight,Qt=kt.scrollTop,Xt=wt.scrollTop,qt=K.top,Kt=function(t,e,n){return Math.max(e,Math.min(n,t))};B.forEach(function(t){var n,i,r,c,l,o,u,s,v;if(C){var h=null,g=null,f=null;if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){var p=t.split(e.DEVIATION_BADGE_SEPARATOR),b=p[0],R=p[1],x=p[2],m="".concat(b).concat(e.DEVIATION_BADGE_SEPARATOR).concat(R);h=null===(n=A.current[m])||void 0===n?void 0:n.current,f=null!==(i=O(b,R))&&void 0!==i?i:D(x),g=Number((null==x?void 0:x.split("-")[0])||0)}else g=Number(t),h=null===(r=A.current[g])||void 0===r?void 0:r.current,f=M(g);if(!h)return;var B=document.querySelectorAll('[id^="guideline-target-"]');B.forEach(function(n,i){var r=h.getBoundingClientRect(),c=n.getBoundingClientRect(),l=r.right-K.left,o=c.left-K.left-0,u=l+75,a=r.top+r.height/2,d=c.top+c.height/2,s=a-Vt+Qt,v=d-Yt+Xt,g="conn-guide-".concat(t,"-").concat(i),p="";"string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)?p=(t.split(e.DEVIATION_BADGE_SEPARATOR)[2]||"").split("-").map(function(t){return Number(t)+1}).join("."):p=String(Number(t)+1);var b=String.fromCharCode(97+i),A=1===B.length?null:"".concat(p,"(").concat(b,")");Gt.push({lhsScrollY:s,rhsScrollY:v,x1:l,x2:o,containerTop:qt,leftIdx:t,rhsArrayIdx:i,styleColor:(null==f?void 0:f.badgeBorder)||"#6366F1",styleBg:(null==f?void 0:f.badgeBg)||"#FFFFFF",styleText:(null==f?void 0:f.badgeText)||"#A16207",styleId:g,centerX:u});var y=Kt(a,Vt,jt),R=Kt(d,Yt,zt),x=y-qt,m=R-qt,S=Rt(l,x,o,m,u,a>=Vt-4&&a<=jt+4,d>=Yt-4&&d<=zt+4);Pt.push({id:g,pathD:S,style:f,leftIdx:t,rhsArrayIdx:i,x1:l,x2:o,y1:x,y2:m,centerX:u,matchLabel:A,isGuideline:!0})})}else if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){var S=t.split(e.DEVIATION_BADGE_SEPARATOR),I=(b=S[0],R=S[1],x=S[2],S[3],m="".concat(b).concat(e.DEVIATION_BADGE_SEPARATOR).concat(R),null===(c=A.current[m])||void 0===c?void 0:c.current),E=null===(l=y.current[m])||void 0===l?void 0:l.current;if(!I||!E)return;var L=I.getBoundingClientRect(),_=E.getBoundingClientRect(),F=null!==(o=O(b,R))&&void 0!==o?o:D(x),N=L.right-K.left,H=_.left-K.left-0,P=N+75,k=L.top+L.height/2,w=_.top+_.height/2,G=k-Vt+Qt,V=w-Yt+Xt,Y="conn-subsec-".concat(m),j=((x||"").split("-").map(function(t){return Number(t)+1}).join("."),null);Gt.push({lhsScrollY:G,rhsScrollY:V,x1:N,x2:H,containerTop:qt,leftIdx:t,rhsArrayIdx:t,styleColor:(null==F?void 0:F.badgeBorder)||"#6366F1",styleBg:(null==F?void 0:F.badgeBg)||"#FFFFFF",styleText:(null==F?void 0:F.badgeText)||"#A16207",styleId:Y,centerX:P});var z=Kt(k,Vt,jt),Q=Kt(w,Yt,zt),X=Rt(N,Z=z-qt,H,$=Q-qt,P,k>=Vt-4&&k<=jt+4,w>=Yt-4&&w<=zt+4);Pt.push({id:Y,pathD:X,style:F,leftIdx:t,rhsArrayIdx:t,x1:N,x2:H,y1:Z,y2:$,matchLabel:j})}else if(T){var q=t,J=a[q];if(!(null===(v=null==J?void 0:J.refIndexes)||void 0===v?void 0:v.length))return;J.refIndexes.forEach(function(e,n){var i,r,c=d.findIndex(function(t){return t.selfIndex===e});if(-1!==c){var l=null===(i=A.current[q])||void 0===i?void 0:i.current,o=null===(r=y.current[c])||void 0===r?void 0:r.current;if(l&&o){var u=l.getBoundingClientRect(),a=o.getBoundingClientRect(),s=M(q),v=u.right-K.left,h=a.left-K.left-0,g=v+75,f=u.top+u.height/2,p=a.top+a.height/2,b=f-Vt+Qt,R=p-Yt+Xt,x="conn-".concat(q,"-").concat(c),m=String(Number(t)+1),B=String.fromCharCode(97+n),S=1===J.refIndexes.length?null:"".concat(m,"(").concat(B,")");Gt.push({lhsScrollY:b,rhsScrollY:R,x1:v,x2:h,containerTop:qt,leftIdx:q,rhsArrayIdx:c,styleColor:(null==s?void 0:s.badgeBorder)||"#6366F1",styleBg:(null==s?void 0:s.badgeBg)||"#FFFFFF",styleText:(null==s?void 0:s.badgeText)||"#A16207",styleId:x,centerX:g});var I=Kt(f,Vt,jt),T=Kt(p,Yt,zt),C=I-qt,E=T-qt,D=Rt(v,C,h,E,g,f>=Vt-4&&f<=jt+4,p>=Yt-4&&p<=zt+4);Pt.push({id:x,pathD:D,style:s,leftIdx:q,rhsArrayIdx:c,x1:v,x2:h,y1:C,y2:E,matchLabel:S})}}})}else{var U=t,W=U;I=null===(u=A.current[U])||void 0===u?void 0:u.current,E=null===(s=y.current[W])||void 0===s?void 0:s.current;if(!I||!E)return;L=I.getBoundingClientRect(),_=E.getBoundingClientRect(),F=M(U),N=L.right-K.left,H=_.left-K.left-0,P=N+75,k=L.top+L.height/2,w=_.top+_.height/2,G=k-Vt+Qt,V=w-Yt+Xt,Y="conn-".concat(U,"-").concat(W),String(Number(t)+1),j=null;Gt.push({lhsScrollY:G,rhsScrollY:V,x1:N,x2:H,containerTop:qt,leftIdx:U,rhsArrayIdx:W,styleColor:(null==F?void 0:F.badgeBorder)||"#6366F1",styleBg:(null==F?void 0:F.badgeBg)||"#FFFFFF",styleText:(null==F?void 0:F.badgeText)||"#A16207",styleId:Y,centerX:P});var Z,$;z=Kt(k,Vt,jt),Q=Kt(w,Yt,zt),X=Rt(N,Z=z-qt,H,$=Q-qt,P,k>=Vt-4&&k<=jt+4,w>=Yt-4&&w<=zt+4);Pt.push({id:Y,pathD:X,style:F,leftIdx:U,rhsArrayIdx:W,x1:N,x2:H,y1:Z,y2:$,matchLabel:j})}}),yt.current=Gt}dt(Pt),setTimeout(function(){return mt()},10)}else dt([]),yt.current=[],setTimeout(function(){return mt()},10)}catch(t){console.error("Line render safe fail: ",t)}finally{gt.current=!1}}},[s,a,d,E,Z,$,M,O,T,S,I,B,x,m,C]),mt=t.useCallback(function(){var t,e,n,o,u,a,d,s,v,h,g,f,p,b,A,y,R,x,m,B=yt.current;if(!B.length)return null===(t=l.current["guideline-up-stroke"])||void 0===t||t.setAttribute("visibility","hidden"),null===(e=l.current["guideline-up-badge"])||void 0===e||e.setAttribute("visibility","hidden"),null===(n=l.current["guideline-down-stroke"])||void 0===n||n.setAttribute("visibility","hidden"),void(null===(o=l.current["guideline-down-badge"])||void 0===o||o.setAttribute("visibility","hidden"));if(!_.current){var S=null!==(a=null===(u=r.current)||void 0===u?void 0:u.scrollTop)&&void 0!==a?a:0,I=null!==(s=null===(d=c.current)||void 0===d?void 0:d.scrollTop)&&void 0!==s?s:0,T=null!==(h=null===(v=r.current)||void 0===v?void 0:v.clientHeight)&&void 0!==h?h:1/0,C=null!==(f=null===(g=c.current)||void 0===g?void 0:g.clientHeight)&&void 0!==f?f:1/0,E=null!==(b=null===(p=r.current)||void 0===p?void 0:p.getBoundingClientRect().top)&&void 0!==b?b:0,M=null!==(y=null===(A=c.current)||void 0===A?void 0:A.getBoundingClientRect().top)&&void 0!==y?y:0,D=E+T,O=M+C,L=null===(R=i.current)||void 0===R?void 0:R.getBoundingClientRect(),F=null!==(x=null==L?void 0:L.top)&&void 0!==x?x:0,N=null!==(m=null==L?void 0:L.height)&&void 0!==m?m:1/0,H=function(t,e,n){return Math.max(e,Math.min(n,t))},P=0,k=0,w=0,G=0,V="#6366F1",Y="#A16207",j=!1,z=0;if(B.forEach(function(t){var e=t.lhsScrollY-S+E,n=t.rhsScrollY-I+M,i=l.current[t.styleId+"-stroke"],r=l.current[t.styleId+"-bg"],c=l.current[t.styleId+"-btn"],o=l.current[t.styleId+"-number"];if(i||r){var u=H(e,E,D),a=H(n,M,O),d=u-F,s=a-F,v=e>=E-4&&e<=D+4,h=n>=M-4&&n<=O+4,g=!0;j=!0;var f=t.centerX||t.x1+75;0===w&&(w=t.x1,G=d,z=f,V=t.styleColor,t.styleBg,Y=t.styleText||"#A16207"),n<M-4?(P++,g=!1):n>O+4&&(k++,g=!1);var p=Rt(t.x1,d,t.x2,s,z,v,h);i&&(g&&p?(i.setAttribute("visibility","visible"),i.setAttribute("d",p)):i.setAttribute("visibility","hidden")),r&&(g&&p?(r.setAttribute("visibility","visible"),r.setAttribute("d",p)):r.setAttribute("visibility","hidden")),c&&(v&&g?(c.setAttribute("visibility","visible"),c.setAttribute("y",String(d-12))):c.setAttribute("visibility","hidden")),o&&(v&&g?(o.setAttribute("visibility","visible"),o.setAttribute("transform","translate(".concat(t.x2-42,", ").concat(s,")"))):o.setAttribute("visibility","hidden"))}}),j&&z>0){var Q=l.current["guideline-up-stroke"],X=l.current["guideline-up-badge"],q=l.current["guideline-up-arrow"],K=l.current["guideline-up-text"],J=l.current["guideline-up-badge-rect"];if(P>0){var U=Math.max(15,M-F+15),W=Math.min(15,Math.abs(z-w),Math.max(0,G-U)),Z="M ".concat(w,",").concat(G," L ").concat(z-W,",").concat(G," Q ").concat(z,",").concat(G," ").concat(z,",").concat(G-W," L ").concat(z,",").concat(U);null==Q||Q.setAttribute("visibility","visible"),null==Q||Q.setAttribute("d",Z),null==Q||Q.setAttribute("stroke",V),null==X||X.setAttribute("visibility","visible"),null==X||X.setAttribute("transform","translate(".concat(z,", ").concat(U,")")),q&&q.setAttribute("fill",V),K&&(K.textContent="+".concat(P),K.setAttribute("fill",Y)),J&&J.setAttribute("stroke",V)}else null==Q||Q.setAttribute("visibility","hidden"),null==X||X.setAttribute("visibility","hidden");var $=l.current["guideline-down-stroke"],tt=l.current["guideline-down-badge"],et=l.current["guideline-down-arrow"],nt=l.current["guideline-down-text"],it=l.current["guideline-down-badge-rect"];if(k>0){var rt=Math.min(N-15,O-F-15);W=Math.min(15,Math.abs(z-w),Math.max(0,rt-G)),Z="M ".concat(w,",").concat(G," L ").concat(z-W,",").concat(G," Q ").concat(z,",").concat(G," ").concat(z,",").concat(G+W," L ").concat(z,",").concat(rt);null==$||$.setAttribute("visibility","visible"),null==$||$.setAttribute("d",Z),null==$||$.setAttribute("stroke",V),null==tt||tt.setAttribute("visibility","visible"),null==tt||tt.setAttribute("transform","translate(".concat(z,", ").concat(rt,")")),et&&et.setAttribute("fill",V),nt&&(nt.textContent="+".concat(k),nt.setAttribute("fill",Y)),it&&it.setAttribute("stroke",V)}else null==$||$.setAttribute("visibility","hidden"),null==tt||tt.setAttribute("visibility","hidden")}}},[]),Bt=t.useCallback(function(){yt.current.length>0&&!_.current||(null!==bt.current&&clearTimeout(bt.current),bt.current=setTimeout(function(){Y.current(),bt.current=null},50))},[]),St=t.useCallback(function(t){if(null!==U.current&&W.current&&Math.abs(t.currentTarget.scrollTop-U.current)<=2){var n=W.current;U.current=null,W.current=null,n()}if(!pt.current&&!z.current){if(T&&Q&&(F.current||B.size>0)){var l=t.currentTarget,o=r.current,u=c.current,a=l===o?u:l===u?o:null;if(l&&a){var d=function(){var t,n,i,r,c,l,o,u,a,d,s,v=P.current,h=k.current;if(null===v)return{leftAnchor:null,rightAnchor:null};if("string"==typeof v&&v.includes(e.DEVIATION_BADGE_SEPARATOR)){var x=v.split(e.DEVIATION_BADGE_SEPARATOR),m="".concat(x[0]).concat(e.DEVIATION_BADGE_SEPARATOR).concat(x[1]);return{leftAnchor:(null===(t=A.current[m])||void 0===t?void 0:t.current)||(null===(n=p.current[x[2]])||void 0===n?void 0:n.current)||(null===(i=g.current[Number(x[2])])||void 0===i?void 0:i.current)||null,rightAnchor:(null===(r=y.current[m])||void 0===r?void 0:r.current)||(null===(c=b.current[x[3]])||void 0===c?void 0:c.current)||(null===(l=f.current[Number(x[3])])||void 0===l?void 0:l.current)||null}}var B=Number(v),S=null!==h?Number(h):B;return{leftAnchor:(null===(o=A.current[B])||void 0===o?void 0:o.current)||(null===(u=R.current[B])||void 0===u?void 0:u.current)||(null===(a=g.current[B])||void 0===a?void 0:a.current)||null,rightAnchor:(null===(d=y.current[S])||void 0===d?void 0:d.current)||(null===(s=f.current[S])||void 0===s?void 0:s.current)||null}}(),s=d.leftAnchor,v=d.rightAnchor,h=l===o?s:v,x=l===o?v:s,m=null;if(h&&x){var S=h.getBoundingClientRect(),I=x.getBoundingClientRect(),C=a.getBoundingClientRect(),E=S.top+S.height/2;m=I.top-C.top+a.scrollTop+I.height/2-(E-C.top)}else{var M=Math.max(0,l.scrollHeight-l.clientHeight),D=Math.max(0,a.scrollHeight-a.clientHeight);m=M>0?l.scrollTop/M*D:l.scrollTop}var O=Math.max(0,a.scrollHeight-a.clientHeight);m=Math.max(0,Math.min(m,O)),Math.abs(a.scrollTop-m)>1&&(pt.current=!0,a.scrollTop=m,requestAnimationFrame(function(){pt.current=!1}))}}T||Bt(),ft.current||(ft.current=!0,requestAnimationFrame(function(){var t,n,l,o,u,a,d;if(F.current){var s=r.current,v=c.current;if(s&&v&&H.current){if(!N.current){var h=P.current,g=void 0;if("string"==typeof h&&h.includes(e.DEVIATION_BADGE_SEPARATOR)){var f=h.split(e.DEVIATION_BADGE_SEPARATOR),p="".concat(f[0]).concat(e.DEVIATION_BADGE_SEPARATOR).concat(f[1]);g=null===(t=A.current[p])||void 0===t?void 0:t.current}else g=null===(n=A.current[h])||void 0===n?void 0:n.current;if(g){var b=g.getBoundingClientRect();N.current={badgeScreenY:b.top+b.height/2,initialScrollTop:s.scrollTop,leftTop:s.getBoundingClientRect().top,leftBottom:s.getBoundingClientRect().top+s.clientHeight,cTop:null!==(o=null===(l=i.current)||void 0===l?void 0:l.getBoundingClientRect().top)&&void 0!==o?o:0}}}if(N.current){var y=N.current,R=s.scrollTop-y.initialScrollTop,x=y.badgeScreenY-R,m=((u=x,a=y.leftTop,d=y.leftBottom,Math.max(a,Math.min(d,u)))-y.cTop).toString(),B=x>=y.leftTop-4&&x<=y.leftBottom+4;H.current.setAttribute("y1",m),H.current.setAttribute("y2",m),H.current.setAttribute("visibility",B?"visible":"hidden")}}}mt(),ft.current=!1}))}},[mt,T,Q,B,Bt]);return t.useEffect(function(){Y.current=xt},[xt]),t.useEffect(function(){var t=setTimeout(Bt,250),e=function(){return X.current()};return window.addEventListener("resize",e),function(){clearTimeout(t),null!==bt.current&&clearTimeout(bt.current),null!==j.current&&clearTimeout(j.current),window.removeEventListener("resize",e)}},[q,K,J,s,x,m,a,d,Z,Bt,S,I,L,B]),{lines:et,setLines:nt,overallConnector:rt,setOverallConnector:ct,connectedLines:at,setConnectedLines:dt,svgDimensions:vt,cachedConnectedPositions:yt,calculateLines:xt,calculateLinesRef:Y,calculateLinesDebounced:Bt,handleColumnScroll:St}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../CognitiveComparehelpers.js"),n=require("../Guidelines/utils/guidelineTargets.js");exports.useLinesCalculator=function(i){var r=i.containerRef,c=i.leftContainerRef,l=i.rightContainerRef;i.svgContainerRef;var o=i.pathRefs,u=i.leftHeaderRef,a=i.rightHeaderRef,d=i.proposedSections,s=i.existingSections,v=i.visibleFields,g=i.leftRefs,h=i.rightRefs,f=i.sectionLeftRefs,p=i.sectionRightRefs,b=i.subSectionLeftRefs,A=i.subSectionRightRefs,y=i.lhsBadgeRefs,R=i.rhsBadgeRefs,x=i.sectionRowRefs,m=i.expandedSections,B=i.expandedSubSections,S=i.connectedSections,T=i.isSideBySide,I=i.activeSideBySideSection,C=i.maintainRelativeOrder,E=i.isGuidelineMode,M=i.cognitiveMap,D=i.getSectionCompareStyle,O=i.getSubSectionCompareStyle,L=i.getDeviationStyleByKey,_=i.isArrowVisible,F=i.isAnimatingRef,N=i.isSideBySideRef,H=i.sideBySideCacheRef,P=i.sideBySideLineRef,k=i.activeSideBySideSectionRef,w=i.activeSideBySideRightSectionRef,G=i.connectedLines,V=i.setConnectedLines,Y=i.cachedConnectedPositions,j=i.calculateLinesRef,z=i.resizeTimerRef,Q=i.scrollLock,X=i.scrollSyncLocked,q=i.handleResizeRef,K=i.activeProposed,J=i.existingRule,U=i.analysisData,W=i.pendingScrollTargetRef,Z=i.pendingScrollCallbackRef,$=i.resolvedComparisonConfig,tt=i.getFieldData,et=t.useState([]),nt=et[0],it=et[1],rt=t.useState(null),ct=rt[0],lt=rt[1],ot=t.useState([]),ut=ot[0],at=ot[1],dt=null!=G?G:ut,st=null!=V?V:at,vt=t.useState({width:0,height:0}),gt=vt[0],ht=vt[1],ft=t.useRef(!1),pt=t.useRef(!1),bt=t.useRef(!1),At=t.useRef(null),yt=t.useRef([]),Rt=null!=Y?Y:yt,xt=function(t,e,n,i,r,c,l){if(Math.abs(i-e)<=1)return c&&l?"M ".concat(t,",").concat(e," L ").concat(n,",").concat(i):c&&!l?"M ".concat(t,",").concat(e," L ").concat(r,",").concat(e):!c&&l?"M ".concat(r,",").concat(e," L ").concat(n,",").concat(i):"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i);var o=Math.min(15,Math.abs(r-t),Math.abs(i-e)/2),u=Math.min(15,Math.abs(n-r),Math.abs(i-e)/2),a=i>e?o:-o,d=i>e?u:-u,s=n>r?u:-u;return c&&l?"M ".concat(t,",").concat(e," L ").concat(r-o,",").concat(e," Q ").concat(r,",").concat(e," ").concat(r,",").concat(e+a," L ").concat(r,",").concat(i-d," Q ").concat(r,",").concat(i," ").concat(r+s,",").concat(i," L ").concat(n,",").concat(i):c&&!l?"M ".concat(t,",").concat(e," L ").concat(r-o,",").concat(e," Q ").concat(r,",").concat(e," ").concat(r,",").concat(e+a," L ").concat(r,",").concat(i):!c&&l?"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i-d," Q ").concat(r,",").concat(i," ").concat(r+s,",").concat(i," L ").concat(n,",").concat(i):"M ".concat(r,",").concat(e," L ").concat(r,",").concat(i)},mt=t.useCallback(function(){var t,i,o,x,_,N,H,P,k,w,G,V,Y,j,z,Q,X,q;if(!ft.current&&!F.current){ft.current=!0;try{if(!r.current)return;var K=function(t){var e=t.split("-"),n=e[0];if(!m[n]&&!1===C)return!1;if(C&&!m["left-".concat(n)]&&!m["right-".concat(n)]&&!m[n])return!1;for(var i=n,r=1;r<e.length-1;r++)if(i+="-".concat(e[r]),!B[i])return!1;return!0},J=r.current.getBoundingClientRect();ht({width:J.width,height:J.height});var U=[];if(v.forEach(function(t){var e,n,i=t.key,r=null===(e=g.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;r&&c&&(r.style.height="auto",c.style.height="auto",r.style.minHeight="0px",c.style.minHeight="0px")}),!F.current){for(var W=0;W<Math.max(d.length,s.length);W++){var Z=null===(t=f.current[W])||void 0===t?void 0:t.current,$=null===(i=p.current[W])||void 0===i?void 0:i.current;Z&&(Z.style.height="auto",Z.style.minHeight="0px"),$&&($.style.height="auto",$.style.minHeight="0px")}C||Object.keys(b.current).forEach(function(t){var e,n;if(K(t)){var i=null===(e=b.current[t])||void 0===e?void 0:e.current,r=null===(n=A.current[t])||void 0===n?void 0:n.current;i&&r&&(i.style.height="auto",r.style.height="auto",i.style.minHeight="0px",r.style.minHeight="0px")}})}var tt={};v.forEach(function(t){var e,n,i=t.key,r=null===(e=g.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;if(r&&c){var l=r.getBoundingClientRect(),o=c.getBoundingClientRect();tt[i]=Math.max(l.height,o.height)}});var et={left:{},right:{}},nt={};if(!F.current)if(C){if(T&&null!==I)if("number"==typeof I){var rt=I,ct=d[rt],ot=null===(_=f.current[rt])||void 0===_?void 0:_.current;ot&&ct&&(ct.refIndexes||[]).forEach(function(t){var e,n=s.findIndex(function(e){return e.selfIndex===t}),i=null===(e=p.current[n])||void 0===e?void 0:e.current;if(i&&(m["left-".concat(rt)]||m["right-".concat(n)])){var r=Math.max(ot.getBoundingClientRect().height,i.getBoundingClientRect().height);et.left[rt]=Math.max(et.left[rt]||0,r),et.right[n]=Math.max(et.right[n]||0,r)}})}else{var ut=I.split(e.DEVIATION_BADGE_SEPARATOR)[2];if(ut){Z=null===(N=b.current[ut])||void 0===N?void 0:N.current,$=null===(H=A.current[ut])||void 0===H?void 0:H.current;if(Z&&$){at=Math.max(Z.getBoundingClientRect().height,$.getBoundingClientRect().height);nt[ut]=Math.max(nt[ut]||0,at)}}}}else{Object.keys(b.current).forEach(function(t){var e,n;if(K(t)){var i=null===(e=b.current[t])||void 0===e?void 0:e.current,r=null===(n=A.current[t])||void 0===n?void 0:n.current;if(i&&r&&null!==i.offsetParent&&null!==r.offsetParent){var c=i.getBoundingClientRect(),l=r.getBoundingClientRect(),o=Math.max(c.height,l.height);nt[t]=o,i.style.minHeight="".concat(o,"px"),r.style.minHeight="".concat(o,"px")}}});for(W=0;W<Math.min(d.length,s.length);W++){var Z=null===(o=f.current[W])||void 0===o?void 0:o.current,$=null===(x=p.current[W])||void 0===x?void 0:x.current;if(Z&&$){var at=Math.max(Z.getBoundingClientRect().height,$.getBoundingClientRect().height);et.left[W]=at,et.right[W]=at}}}if(v.forEach(function(t){var e,n,i=t.key,r=null===(e=g.current[i])||void 0===e?void 0:e.current,c=null===(n=h.current[i])||void 0===n?void 0:n.current;if(r&&c){var l=tt[i];r.style.minHeight="".concat(l,"px"),c.style.minHeight="".concat(l,"px")}}),F.current||(Object.entries(et.left).forEach(function(t){var e,n=t[0],i=t[1],r=null===(e=f.current[Number(n)])||void 0===e?void 0:e.current;r&&(r.style.minHeight="".concat(i,"px"))}),Object.entries(et.right).forEach(function(t){var e,n=t[0],i=t[1],r=null===(e=p.current[Number(n)])||void 0===e?void 0:e.current;r&&(r.style.minHeight="".concat(i,"px"))}),C||Object.keys(nt).forEach(function(t){var e,n,i=null===(e=b.current[t])||void 0===e?void 0:e.current,r=null===(n=A.current[t])||void 0===n?void 0:n.current;if(i&&r&&nt[t]){var c=nt[t];i.style.minHeight="".concat(c,"px"),r.style.minHeight="".concat(c,"px")}})),!E){d.forEach(function(t,e){var n,i=t.continuationSourceRowId?d.findIndex(function(e){return e.comparisonRowId===t.continuationSourceRowId}):-1,r=i>=0?i:e,o=null===(n=f.current[r])||void 0===n?void 0:n.current;if(o){var u=function(t,e){if(!C)return s[e]?[e]:[];var n=(t.refIndexes||[]).map(function(t){return s.findIndex(function(e){return e.selfIndex===t})}).filter(function(t){return-1!==t});return!n.length&&s[e]?[e]:Array.from(new Set(n))}(t,e);u.forEach(function(t){var n,u,a,v,g,h,f,b,A,y,R,x,m=null===(n=p.current[t])||void 0===n?void 0:n.current;if(m){var B=o.getBoundingClientRect(),S=m.getBoundingClientRect(),E=B.right-J.left,O=S.left-J.left,L=B.top+18-J.top,_=S.top+18-J.top;if(C&&T&&I===e){var F=null!==(a=null===(u=c.current)||void 0===u?void 0:u.getBoundingClientRect().top)&&void 0!==a?a:0,N=null!==(g=null===(v=l.current)||void 0===v?void 0:v.getBoundingClientRect().top)&&void 0!==g?g:0,H=F+(null!==(f=null===(h=c.current)||void 0===h?void 0:h.clientHeight)&&void 0!==f?f:1/0),P=N+(null!==(A=null===(b=l.current)||void 0===b?void 0:b.clientHeight)&&void 0!==A?A:1/0),k=function(t,e,n){return Math.max(e,Math.min(n,t))};L=k(B.top+18,F,H)-J.top,_=k(S.top+18,N,P)-J.top}var w=D(r);w&&U.push({id:"line-".concat(r,"-").concat(t),x1:E,y1:L,x2:O,y2:_,style:w,sectionIdx:r,targetRightIdx:t,isSubSection:!1,isMappingContinuation:i>=0,hasCognitive:!!((null===(y=d[r])||void 0===y?void 0:y.cognitiveData)||(null===(R=s[t])||void 0===R?void 0:R.cognitiveData)||(null===(x=d[r])||void 0===x?void 0:x.nodeId)&&M[d[r].nodeId])})}})}})}if(!E&&T&&"string"==typeof I&&I.includes(e.DEVIATION_BADGE_SEPARATOR)){var dt=I.split(e.DEVIATION_BADGE_SEPARATOR),vt=dt[0],gt=dt[1],pt=dt[2],bt=(dt[3],"".concat(vt).concat(e.DEVIATION_BADGE_SEPARATOR).concat(gt)),At=null===(P=y.current[bt])||void 0===P?void 0:P.current,yt=null===(k=R.current[bt])||void 0===k?void 0:k.current;if(At&&yt){var mt=At.getBoundingClientRect(),St=yt.getBoundingClientRect(),Tt=mt.right-J.left,It=St.left-J.left,Ct=mt.top+mt.height/2-J.top,Et=St.top+St.height/2-J.top;if(C){var Mt=null!==(G=null===(w=c.current)||void 0===w?void 0:w.getBoundingClientRect().top)&&void 0!==G?G:0,Dt=null!==(Y=null===(V=l.current)||void 0===V?void 0:V.getBoundingClientRect().top)&&void 0!==Y?Y:0,Ot=Mt+(null!==(z=null===(j=c.current)||void 0===j?void 0:j.clientHeight)&&void 0!==z?z:1/0),Lt=Dt+(null!==(X=null===(Q=l.current)||void 0===Q?void 0:Q.clientHeight)&&void 0!==X?X:1/0),_t=function(t,e,n){return Math.max(e,Math.min(n,t))};Ct=_t(mt.top+mt.height/2,Mt,Ot)-J.top,Et=_t(St.top+St.height/2,Dt,Lt)-J.top}var Ft=null!==(q=L(vt,gt))&&void 0!==q?q:O(pt);Ft&&U.push({id:"line-subsec-".concat(bt),x1:Tt,y1:Ct,x2:It,y2:Et,style:Ft,sectionIdx:Number(pt.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(it(U),u.current&&a.current){var Nt=u.current.getBoundingClientRect(),Ht=a.current.getBoundingClientRect(),Pt=(Nt.top+Nt.height/2-J.top+Ht.top+Ht.height/2-J.top)/2;lt({x1:Nt.right-J.left,x2:Ht.left-J.left,y:Pt})}else lt(null);if(S.size>0){var kt=[],wt=c.current,Gt=l.current;if(wt&&Gt){var Vt=[],Yt=wt.getBoundingClientRect().top,jt=Gt.getBoundingClientRect().top,zt=Yt+wt.clientHeight,Qt=jt+Gt.clientHeight,Xt=wt.scrollTop,qt=Gt.scrollTop,Kt=J.top,Jt=function(t,e,n){return Math.max(e,Math.min(n,t))};S.forEach(function(t){var i,r,c,l,o,u,a,v,g;if(E){var h=null,f=null,p=null;if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){var b=t.split(e.DEVIATION_BADGE_SEPARATOR),A=b[0],x=b[1],m=b[2],B="".concat(A).concat(e.DEVIATION_BADGE_SEPARATOR).concat(x);h=null===(i=y.current[B])||void 0===i?void 0:i.current,p=null!==(r=L(A,x))&&void 0!==r?r:O(m),f=Number((null==m?void 0:m.split("-")[0])||0)}else f=Number(t),h=null===(c=y.current[f])||void 0===c?void 0:c.current,p=D(f);if(!h)return;var S=n.getVisibleGuidelineTargets(Gt);S.forEach(function(n,i){var r=h.getBoundingClientRect(),c=n.getBoundingClientRect(),l=r.right-J.left,o=c.left-J.left-0,u=l+75,a=r.top+r.height/2,d=c.top+c.height/2,s=a-Yt+Xt,v=d-jt+qt,g="conn-guide-".concat(t,"-").concat(i),f="";"string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)?f=(t.split(e.DEVIATION_BADGE_SEPARATOR)[2]||"").split("-").map(function(t){return Number(t)+1}).join("."):f=String(Number(t)+1);var b=String.fromCharCode(97+i),A=1===S.length?null:"".concat(f,"(").concat(b,")");Vt.push({lhsScrollY:s,rhsScrollY:v,x1:l,x2:o,containerTop:Kt,leftIdx:t,rhsArrayIdx:i,styleColor:(null==p?void 0:p.badgeBorder)||"#6366F1",styleBg:(null==p?void 0:p.badgeBg)||"#FFFFFF",styleText:(null==p?void 0:p.badgeText)||"#A16207",styleId:g,centerX:u});var y=Jt(a,Yt,zt),R=Jt(d,jt,Qt),x=y-Kt,m=R-Kt,B=xt(l,x,o,m,u,a>=Yt-4&&a<=zt+4,d>=jt-4&&d<=Qt+4);kt.push({id:g,pathD:B,style:p,leftIdx:t,rhsArrayIdx:i,x1:l,x2:o,y1:x,y2:m,centerX:u,matchLabel:A,isGuideline:!0})})}else if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){var T=t.split(e.DEVIATION_BADGE_SEPARATOR),I=(A=T[0],x=T[1],m=T[2],T[3],B="".concat(A).concat(e.DEVIATION_BADGE_SEPARATOR).concat(x),null===(l=y.current[B])||void 0===l?void 0:l.current),M=null===(o=R.current[B])||void 0===o?void 0:o.current;if(!I||!M)return;var _=I.getBoundingClientRect(),F=M.getBoundingClientRect(),N=null!==(u=L(A,x))&&void 0!==u?u:O(m),H=_.right-J.left,P=F.left-J.left-0,k=H+75,w=_.top+_.height/2,G=F.top+F.height/2,V=w-Yt+Xt,Y=G-jt+qt,j="conn-subsec-".concat(B),z=((m||"").split("-").map(function(t){return Number(t)+1}).join("."),null);Vt.push({lhsScrollY:V,rhsScrollY:Y,x1:H,x2:P,containerTop:Kt,leftIdx:t,rhsArrayIdx:t,styleColor:(null==N?void 0:N.badgeBorder)||"#6366F1",styleBg:(null==N?void 0:N.badgeBg)||"#FFFFFF",styleText:(null==N?void 0:N.badgeText)||"#A16207",styleId:j,centerX:k});var Q=Jt(w,Yt,zt),X=Jt(G,jt,Qt),q=xt(H,$=Q-Kt,P,tt=X-Kt,k,w>=Yt-4&&w<=zt+4,G>=jt-4&&G<=Qt+4);kt.push({id:j,pathD:q,style:N,leftIdx:t,rhsArrayIdx:t,x1:H,x2:P,y1:$,y2:tt,matchLabel:z})}else if(C){var K=t,U=d[K];if(!(null===(g=null==U?void 0:U.refIndexes)||void 0===g?void 0:g.length))return;U.refIndexes.forEach(function(e,n){var i,r,c=s.findIndex(function(t){return t.selfIndex===e});if(-1!==c){var l=null===(i=y.current[K])||void 0===i?void 0:i.current,o=null===(r=R.current[c])||void 0===r?void 0:r.current;if(l&&o){var u=l.getBoundingClientRect(),a=o.getBoundingClientRect(),d=D(K),v=u.right-J.left,g=a.left-J.left-0,h=v+75,f=u.top+u.height/2,p=a.top+a.height/2,b=f-Yt+Xt,A=p-jt+qt,x="conn-".concat(K,"-").concat(c),m=String(Number(t)+1),B=String.fromCharCode(97+n),S=1===U.refIndexes.length?null:"".concat(m,"(").concat(B,")");Vt.push({lhsScrollY:b,rhsScrollY:A,x1:v,x2:g,containerTop:Kt,leftIdx:K,rhsArrayIdx:c,styleColor:(null==d?void 0:d.badgeBorder)||"#6366F1",styleBg:(null==d?void 0:d.badgeBg)||"#FFFFFF",styleText:(null==d?void 0:d.badgeText)||"#A16207",styleId:x,centerX:h});var T=Jt(f,Yt,zt),I=Jt(p,jt,Qt),C=T-Kt,E=I-Kt,M=xt(v,C,g,E,h,f>=Yt-4&&f<=zt+4,p>=jt-4&&p<=Qt+4);kt.push({id:x,pathD:M,style:d,leftIdx:K,rhsArrayIdx:c,x1:v,x2:g,y1:C,y2:E,matchLabel:S})}}})}else{var W=t,Z=W;I=null===(a=y.current[W])||void 0===a?void 0:a.current,M=null===(v=R.current[Z])||void 0===v?void 0:v.current;if(!I||!M)return;_=I.getBoundingClientRect(),F=M.getBoundingClientRect(),N=D(W),H=_.right-J.left,P=F.left-J.left-0,k=H+75,w=_.top+_.height/2,G=F.top+F.height/2,V=w-Yt+Xt,Y=G-jt+qt,j="conn-".concat(W,"-").concat(Z),String(Number(t)+1),z=null;Vt.push({lhsScrollY:V,rhsScrollY:Y,x1:H,x2:P,containerTop:Kt,leftIdx:W,rhsArrayIdx:Z,styleColor:(null==N?void 0:N.badgeBorder)||"#6366F1",styleBg:(null==N?void 0:N.badgeBg)||"#FFFFFF",styleText:(null==N?void 0:N.badgeText)||"#A16207",styleId:j,centerX:k});var $,tt;Q=Jt(w,Yt,zt),X=Jt(G,jt,Qt),q=xt(H,$=Q-Kt,P,tt=X-Kt,k,w>=Yt-4&&w<=zt+4,G>=jt-4&&G<=Qt+4);kt.push({id:j,pathD:q,style:N,leftIdx:W,rhsArrayIdx:Z,x1:H,x2:P,y1:$,y2:tt,matchLabel:z})}}),Rt.current=Vt}st(kt),setTimeout(function(){return Bt()},10)}else st([]),Rt.current=[],setTimeout(function(){return Bt()},10)}catch(t){console.error("Line render safe fail: ",t)}finally{ft.current=!1}}},[v,d,s,M,$,tt,D,L,C,T,I,S,m,B,E]),Bt=t.useCallback(function(){var t,e,n,i,u,a,d,s,v,g,h,f,p,b,A,y,R,x,m,B=Rt.current;if(!B.length)return null===(t=o.current["guideline-up-stroke"])||void 0===t||t.setAttribute("visibility","hidden"),null===(e=o.current["guideline-up-badge"])||void 0===e||e.setAttribute("visibility","hidden"),null===(n=o.current["guideline-down-stroke"])||void 0===n||n.setAttribute("visibility","hidden"),void(null===(i=o.current["guideline-down-badge"])||void 0===i||i.setAttribute("visibility","hidden"));if(!F.current){var S=null!==(a=null===(u=c.current)||void 0===u?void 0:u.scrollTop)&&void 0!==a?a:0,T=null!==(s=null===(d=l.current)||void 0===d?void 0:d.scrollTop)&&void 0!==s?s:0,I=null!==(g=null===(v=c.current)||void 0===v?void 0:v.clientHeight)&&void 0!==g?g:1/0,C=null!==(f=null===(h=l.current)||void 0===h?void 0:h.clientHeight)&&void 0!==f?f:1/0,E=null!==(b=null===(p=c.current)||void 0===p?void 0:p.getBoundingClientRect().top)&&void 0!==b?b:0,M=null!==(y=null===(A=l.current)||void 0===A?void 0:A.getBoundingClientRect().top)&&void 0!==y?y:0,D=E+I,O=M+C,L=null===(R=r.current)||void 0===R?void 0:R.getBoundingClientRect(),_=null!==(x=null==L?void 0:L.top)&&void 0!==x?x:0,N=null!==(m=null==L?void 0:L.height)&&void 0!==m?m:1/0,H=function(t,e,n){return Math.max(e,Math.min(n,t))},P=0,k=0,w=0,G=0,V="#6366F1",Y="#A16207",j=!1,z=0;if(B.forEach(function(t){var e=t.lhsScrollY-S+E,n=t.rhsScrollY-T+M,i=o.current[t.styleId+"-stroke"],r=o.current[t.styleId+"-bg"],c=o.current[t.styleId+"-btn"],l=o.current[t.styleId+"-number"];if(i||r){var u=H(e,E,D),a=H(n,M,O),d=u-_,s=a-_,v=e>=E-4&&e<=D+4,g=n>=M-4&&n<=O+4,h=!0;j=!0;var f=t.centerX||t.x1+75;0===w&&(w=t.x1,G=d,z=f,V=t.styleColor,t.styleBg,Y=t.styleText||"#A16207"),n<M-4?(P++,h=!1):n>O+4&&(k++,h=!1);var p=xt(t.x1,d,t.x2,s,z,v,g);i&&(h&&p?(i.setAttribute("visibility","visible"),i.setAttribute("d",p)):i.setAttribute("visibility","hidden")),r&&(h&&p?(r.setAttribute("visibility","visible"),r.setAttribute("d",p)):r.setAttribute("visibility","hidden")),c&&(v&&h?(c.setAttribute("visibility","visible"),c.setAttribute("y",String(d-12))):c.setAttribute("visibility","hidden")),l&&(v&&h?(l.setAttribute("visibility","visible"),l.setAttribute("transform","translate(".concat(t.x2-42,", ").concat(s,")"))):l.setAttribute("visibility","hidden"))}}),j&&z>0){var Q=o.current["guideline-up-stroke"],X=o.current["guideline-up-badge"],q=o.current["guideline-up-arrow"],K=o.current["guideline-up-text"],J=o.current["guideline-up-badge-rect"];if(P>0){var U=Math.max(15,M-_+15),W=Math.min(15,Math.abs(z-w),Math.max(0,G-U)),Z="M ".concat(w,",").concat(G," L ").concat(z-W,",").concat(G," Q ").concat(z,",").concat(G," ").concat(z,",").concat(G-W," L ").concat(z,",").concat(U);null==Q||Q.setAttribute("visibility","visible"),null==Q||Q.setAttribute("d",Z),null==Q||Q.setAttribute("stroke",V),null==X||X.setAttribute("visibility","visible"),null==X||X.setAttribute("transform","translate(".concat(z,", ").concat(U,")")),q&&q.setAttribute("fill",V),K&&(K.textContent="+".concat(P),K.setAttribute("fill",Y)),J&&J.setAttribute("stroke",V)}else null==Q||Q.setAttribute("visibility","hidden"),null==X||X.setAttribute("visibility","hidden");var $=o.current["guideline-down-stroke"],tt=o.current["guideline-down-badge"],et=o.current["guideline-down-arrow"],nt=o.current["guideline-down-text"],it=o.current["guideline-down-badge-rect"];if(k>0){var rt=Math.min(N-15,O-_-15);W=Math.min(15,Math.abs(z-w),Math.max(0,rt-G)),Z="M ".concat(w,",").concat(G," L ").concat(z-W,",").concat(G," Q ").concat(z,",").concat(G," ").concat(z,",").concat(G+W," L ").concat(z,",").concat(rt);null==$||$.setAttribute("visibility","visible"),null==$||$.setAttribute("d",Z),null==$||$.setAttribute("stroke",V),null==tt||tt.setAttribute("visibility","visible"),null==tt||tt.setAttribute("transform","translate(".concat(z,", ").concat(rt,")")),et&&et.setAttribute("fill",V),nt&&(nt.textContent="+".concat(k),nt.setAttribute("fill",Y)),it&&it.setAttribute("stroke",V)}else null==$||$.setAttribute("visibility","hidden"),null==tt||tt.setAttribute("visibility","hidden")}}},[]),St=t.useCallback(function(){Rt.current.length>0&&!F.current||(null!==At.current&&clearTimeout(At.current),At.current=setTimeout(function(){j.current(),At.current=null},50))},[]),Tt=t.useCallback(function(t){if(null!==W.current&&Z.current&&Math.abs(t.currentTarget.scrollTop-W.current)<=2){var n=Z.current;W.current=null,Z.current=null,n()}if(!bt.current&&!Q.current){if(C&&X&&(N.current||S.size>0)){var i=t.currentTarget,o=c.current,u=l.current,a=i===o?u:i===u?o:null;if(i&&a){var d=function(){var t,n,i,r,c,l,o,u,a,d,s,v=k.current,g=w.current;if(null===v)return{leftAnchor:null,rightAnchor:null};if("string"==typeof v&&v.includes(e.DEVIATION_BADGE_SEPARATOR)){var h=v.split(e.DEVIATION_BADGE_SEPARATOR),m="".concat(h[0]).concat(e.DEVIATION_BADGE_SEPARATOR).concat(h[1]);return{leftAnchor:(null===(t=y.current[m])||void 0===t?void 0:t.current)||(null===(n=b.current[h[2]])||void 0===n?void 0:n.current)||(null===(i=f.current[Number(h[2])])||void 0===i?void 0:i.current)||null,rightAnchor:(null===(r=R.current[m])||void 0===r?void 0:r.current)||(null===(c=A.current[h[3]])||void 0===c?void 0:c.current)||(null===(l=p.current[Number(h[3])])||void 0===l?void 0:l.current)||null}}var B=Number(v),S=null!==g?Number(g):B;return{leftAnchor:(null===(o=y.current[B])||void 0===o?void 0:o.current)||(null===(u=x.current[B])||void 0===u?void 0:u.current)||(null===(a=f.current[B])||void 0===a?void 0:a.current)||null,rightAnchor:(null===(d=R.current[S])||void 0===d?void 0:d.current)||(null===(s=p.current[S])||void 0===s?void 0:s.current)||null}}(),s=d.leftAnchor,v=d.rightAnchor,g=i===o?s:v,h=i===o?v:s,m=null;if(g&&h){var B=g.getBoundingClientRect(),T=h.getBoundingClientRect(),I=a.getBoundingClientRect(),E=B.top+B.height/2;m=T.top-I.top+a.scrollTop+T.height/2-(E-I.top)}else{var M=Math.max(0,i.scrollHeight-i.clientHeight),D=Math.max(0,a.scrollHeight-a.clientHeight);m=M>0?i.scrollTop/M*D:i.scrollTop}var O=Math.max(0,a.scrollHeight-a.clientHeight);m=Math.max(0,Math.min(m,O)),Math.abs(a.scrollTop-m)>1&&(bt.current=!0,a.scrollTop=m,requestAnimationFrame(function(){bt.current=!1}))}}C||St(),pt.current||(pt.current=!0,requestAnimationFrame(function(){var t,n,i,o,u,a,d;if(N.current){var s=c.current,v=l.current;if(s&&v&&P.current){if(!H.current){var g=k.current,h=void 0;if("string"==typeof g&&g.includes(e.DEVIATION_BADGE_SEPARATOR)){var f=g.split(e.DEVIATION_BADGE_SEPARATOR),p="".concat(f[0]).concat(e.DEVIATION_BADGE_SEPARATOR).concat(f[1]);h=null===(t=y.current[p])||void 0===t?void 0:t.current}else h=null===(n=y.current[g])||void 0===n?void 0:n.current;if(h){var b=h.getBoundingClientRect();H.current={badgeScreenY:b.top+b.height/2,initialScrollTop:s.scrollTop,leftTop:s.getBoundingClientRect().top,leftBottom:s.getBoundingClientRect().top+s.clientHeight,cTop:null!==(o=null===(i=r.current)||void 0===i?void 0:i.getBoundingClientRect().top)&&void 0!==o?o:0}}}if(H.current){var A=H.current,R=s.scrollTop-A.initialScrollTop,x=A.badgeScreenY-R,m=((u=x,a=A.leftTop,d=A.leftBottom,Math.max(a,Math.min(d,u)))-A.cTop).toString(),B=x>=A.leftTop-4&&x<=A.leftBottom+4;P.current.setAttribute("y1",m),P.current.setAttribute("y2",m),P.current.setAttribute("visibility",B?"visible":"hidden")}}}Bt(),pt.current=!1}))}},[Bt,C,X,S,St]);return t.useEffect(function(){j.current=mt},[mt]),t.useEffect(function(){var t=setTimeout(St,250),e=function(){return q.current()};return window.addEventListener("resize",e),function(){clearTimeout(t),null!==At.current&&clearTimeout(At.current),null!==z.current&&clearTimeout(z.current),window.removeEventListener("resize",e)}},[K,J,U,v,m,B,d,s,$,St,T,I,_,S]),{lines:nt,setLines:it,overallConnector:ct,setOverallConnector:lt,connectedLines:dt,setConnectedLines:st,svgDimensions:gt,cachedConnectedPositions:Rt,calculateLines:mt,calculateLinesRef:j,calculateLinesDebounced:St,handleColumnScroll:Tt}};
2
2
  //# sourceMappingURL=useLinesCalculator.js.map