@viswa-test/test-citation 0.0.44 → 0.0.45

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),t=require("react"),i=require("@mui/material"),r=require("lucide-react"),o=require("../../assests/svg/ButtonCognitiveIcon.js"),l=require("./OverlayComponent.js"),s=require("react-markdown"),a=require("./CognitiveComparehelpers.js"),c=require("./CognitiveCompareConfig.js"),u=require("./CognitivePopup.js"),d=require("./MoreFunctionsPopup.js"),v=require("./LoaderComponent.js"),f=require("rehype-raw");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=p(t),g=p(s),x=p(f),_="::",m=h.default.memo(function(o){var l=o.content,s=o.sxStyles,c=o.deviationBadges,u=void 0===c?[]:c,d=o.highlights,v=void 0===d?[]:d,f=o.maintainRelativeOrder,p=void 0===f||f,h=t.useMemo(function(){return u.reduce(function(n,t){var i;return e.__assign(e.__assign({},n),((i={})[t.id]=t,i))},{})},[u]),_=t.useMemo(function(){return{mark:function(t){var i=t.children;return n.jsx("span",e.__assign({style:{backgroundColor:"#fccccc",borderRadius:"2px"}},{children:i}))},span:function(t){var o,l,s,a,c,u=t.children,d=e.__rest(t,["children"]),v=d["data-badge-id"];if(!v)return n.jsx("span",e.__assign({},d,{children:u}));var f=h[v];return f?n.jsxs(i.Box,e.__assign({component:"span",sx:{position:"static",display:"inline"}},{children:[u,n.jsx(i.Box,e.__assign({ref:f.badgeRef,onClick:f.onClick,sx:e.__assign(e.__assign({position:"absolute",zIndex:30,display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"10px",bgcolor:(null===(o=f.style)||void 0===o?void 0:o.badgeBg)||"#EEF2FF",color:(null===(l=f.style)||void 0===l?void 0:l.badgeText)||"#3730A3",border:"1px solid ".concat((null===(s=f.style)||void 0===s?void 0:s.badgeBorder)||"#C7D2FE"),borderRadius:"12px",px:1,py:.3,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",boxShadow:"0 1px 3px rgba(0,0,0,0.07)"},"left"===f.side?{right:"-16px",transform:"translateY(-20%) translateX(calc(100% + 8px))"}:{left:"-16px",transform:"translateY(-20%) translateX(calc(-100% - 8px))"}),f.isConnected&&f.style&&{outline:"2px solid ".concat(f.style.badgeBorder),outlineOffset:"1px"})},{children:n.jsxs(n.Fragment,{children:[n.jsx(i.Box,e.__assign({component:"span",sx:e.__assign({fontSize:"10px",fontWeight:700},"left"===f.side?{pr:.5,borderRight:"1px solid ".concat((null===(a=f.style)||void 0===a?void 0:a.badgeBorder)||"#C7D2FE")}:{})},{children:f.label})),"left"===f.side&&n.jsxs(n.Fragment,{children:[n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"10px",px:.25}},{children:null!=f.score&&"N/A"!==f.score&&"NA"!==f.score&&0!==f.score?"".concat(f.score):f.isOrphan?"No Deviation Found":"N/A"===f.score||"NA"===f.score?"N/A":"Same"})),n.jsx(r.EllipsisVertical,{size:10,color:(null===(c=f.style)||void 0===c?void 0:c.badgeText)||"#3730A3"})]})]})}))]})):n.jsx("span",e.__assign({},d,{children:u}))}}},[h,p]),m=t.useMemo(function(){var e=l||"",n=function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")};return u.forEach(function(t){if(t.highlight){var i=t.highlight.replace(/\\(['’])/g,"$1");e=e.replace(new RegExp(n(i),"g"),'<span data-badge-id="'.concat(t.id,'"><mark>').concat(i,"</mark></span>"))}}),v.forEach(function(t){t&&(e=e.replace(new RegExp(n(t),"g"),"<mark>".concat(t,"</mark>")))}),e},[l,u,v]);return n.jsx(i.Typography,e.__assign({component:"div",sx:e.__assign(e.__assign({},s),{position:"relative",overflow:"visible","& p, & li, & ul, & ol":{position:"static",overflow:"visible"}})},{children:n.jsx(g.default,e.__assign({components:_,rehypePlugins:[x.default]},{children:a.safeStringify(m).replace(/\\n/g,"\n")}))}))},function(e,n){if(e.content!==n.content)return!1;if(e.sxStyles!==n.sxStyles)return!1;if(e.maintainRelativeOrder!==n.maintainRelativeOrder)return!1;var t=e.highlights||[],i=n.highlights||[];if(t.length!==i.length)return!1;for(var r=0;r<t.length;r++)if(t[r]!==i[r])return!1;return!0}),y=function(e,n,t,i,r){void 0===r&&(r=14);var o=e+.5*(t-e),l=i-n;if(Math.abs(l)<3)return"M ".concat(e," ").concat(n," H ").concat(t);var s=l>0?1:-1,a=Math.min(r,Math.abs(l)/2,Math.abs(o-e)/2,Math.abs(t-o)/2);return["M ".concat(e," ").concat(n),"H ".concat(o-a),"Q ".concat(o," ").concat(n," ").concat(o," ").concat(n+s*a),"V ".concat(i-s*a),"Q ".concat(o," ").concat(i," ").concat(o+a," ").concat(i),"H ".concat(t)].join(" ")},b={id:"",title:""},S={open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,isOrphan:!1,docData:null,deviationData:null},R=function(e,n,t,i,r){void 0===t&&(t=300);var o=e.style.scrollBehavior;e.style.scrollBehavior="auto";var l=e.scrollTop,s=n-l,a=null,c=function(u){null===a&&(a=u);var d,v=u-a;v<t?(e.scrollTop=(d=v,d/=t,s*(--d*d*d+1)+l),r&&r(),requestAnimationFrame(c)):(e.scrollTop=n,e.style.scrollBehavior=o,r&&r(),i&&i())};requestAnimationFrame(c)};exports.SHARED_MARKDOWN_STYLES=c.SHARED_MARKDOWN_STYLES,exports.default=function(s){var f,p,g,x,C,I,w,F,B=s.componentHeaderText,j=void 0===B?"Contract Comparison":B,E=s.treeData,T=s.comparisonConfig,A=s.leftColumnTitleText,M=s.rightColumnTitleText,k=s.markdownStyles,D=s.displayConfig,O=void 0===D?{isHeaderVisible:!0,isToggleVisible:!0,maintainRelativeOrder:!1}:D,N=s.popupConfig,H=s.deviationData,L=void 0===H?{}:H,W=t.useState(O.maintainRelativeOrder),z=W[0],P=W[1],q=t.useState(!1),Y=q[0],V=q[1],K=t.useState(!1),U=K[0],G=K[1],X=t.useState(null),J=X[0],$=X[1],Q=t.useState(!1),Z=Q[0],ee=Q[1],ne=t.useState(!1),te=ne[0],ie=ne[1],re=t.useRef(!1),oe=t.useState(null),le=oe[0],se=oe[1],ae=t.useState(new Set),ce=ae[0],ue=ae[1],de=t.useState([]),ve=de[0],fe=de[1],pe=t.useRef(null),he=t.useRef(!1),ge=t.useRef(null),xe=t.useRef({}),_e=t.useRef([]),me=t.useRef(!1),ye=t.useRef(!1),be=t.useRef(null),Se=t.useMemo(function(){return(null==E?void 0:E.cognitive_decisioning)||{}},[E]),Re=t.useState(null),Ce=Re[0],Ie=Re[1],we=t.useRef(null),Fe=t.useState({width:0,height:0}),Be=Fe[0],je=Fe[1],Ee=t.useMemo(function(){return e.__assign(e.__assign({},c.SHARED_MARKDOWN_STYLES),k)},[k]),Te=t.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,isOrphan:!1,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,docData:null,deviationData:null}),Ae=Te[0],Me=Te[1],ke=t.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,isOrphan:!1,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,docData:null,deviationData:null}),De=ke[0],Oe=ke[1],Ne=t.useRef(null),He=t.useRef(null),Le=t.useRef(null),We=t.useRef(null),ze=t.useRef(null),Pe=t.useRef(null),qe=t.useRef(null),Ye=t.useRef(null),Ve=t.useRef(!1),Ke=t.useRef(null);t.useEffect(function(){Ke.current=null},[Ae.sectionIdx,Ae.open]);var Ue=t.useCallback(function(){Ie(null),Me(S),se(null)},[]),Ge=t.useCallback(function(){Oe(S)},[]),Xe=t.useCallback(function(){var e;if(Ae.anchorEl&&Ae.refSectionTitle){var n=Ae.anchorEl.getBoundingClientRect(),t=(null===(e=null==we?void 0:we.current)||void 0===e?void 0:e.offsetHeight)||0,i=Math.min(680,window.innerWidth-24),r=window.innerHeight-n.bottom-12-12,o=n.top-12-12,l=r<t&&o>r;null!==Ke.current?!0===Ke.current&&(l=o>=t||o>=r):l=!(r>=t||r>=o),Ke.current=l;var s=l?o:r,a=Math.min(t||9999,s),c=l?n.top-12-a:n.bottom+12,u=n.left+n.width/2,d=u-i/2,v=Math.max(12,Math.min(d,window.innerWidth-i-12)),f=Math.max(14,Math.min(u-v,i-10-4));Ie({top:c,left:v,arrowLeft:f,openAbove:l,maxHeight:s})}},[Ae.anchorEl,Ae.refSectionTitle]);t.useEffect(function(){if(Ae.open){window.addEventListener("resize",Xe);var e=requestAnimationFrame(Xe),n=null;return we.current&&(n=new ResizeObserver(function(){cancelAnimationFrame(e),e=requestAnimationFrame(Xe)})).observe(we.current),function(){cancelAnimationFrame(e),window.removeEventListener("resize",Xe),n&&n.disconnect()}}},[Ae.open,Xe]),t.useEffect(function(){var e=Ne.current;if(e&&Ae.open){var n=function(e){we.current&&we.current.contains(e.target)||(Ie(null),Ue())};return e.addEventListener("scroll",n,{capture:!0}),window.addEventListener("scroll",n,{capture:!0}),function(){e.removeEventListener("scroll",n,{capture:!0}),window.removeEventListener("scroll",n,{capture:!0})}}},[Ae.open,Ue]),t.useEffect(function(){var e=Ne.current;if(e&&De.open){var n=function(){Ge()};return e.addEventListener("scroll",n,{capture:!0}),window.addEventListener("scroll",n,{capture:!0}),function(){e.removeEventListener("scroll",n,{capture:!0}),window.removeEventListener("scroll",n,{capture:!0})}}},[De.open,Ge]);var Je=t.useMemo(function(){var n,t,i,r,o,l,s,a,u,d,v,f;return{fields:null!==(n=null==T?void 0:T.fields)&&void 0!==n?n:c.DEFAULT_FIELD_CONFIG,thresholds:{high:null!==(i=null===(t=null==T?void 0:T.thresholds)||void 0===t?void 0:t.high)&&void 0!==i?i:c.DEFAULT_COMPARISON_CONFIG.thresholds.high,medium:null!==(o=null===(r=null==T?void 0:T.thresholds)||void 0===r?void 0:r.medium)&&void 0!==o?o:c.DEFAULT_COMPARISON_CONFIG.thresholds.medium,exact:null!==(s=null===(l=null==T?void 0:T.thresholds)||void 0===l?void 0:l.exact)&&void 0!==s?s:c.DEFAULT_COMPARISON_CONFIG.thresholds.exact},relationStyles:{noContent:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.noContent),(null===(a=null==T?void 0:T.relationStyles)||void 0===a?void 0:a.noContent)||{}),high:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.high),(null===(u=null==T?void 0:T.relationStyles)||void 0===u?void 0:u.high)||{}),exact:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.exact),(null===(d=null==T?void 0:T.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.medium),(null===(v=null==T?void 0:T.relationStyles)||void 0===v?void 0:v.medium)||{}),low:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.low),(null===(f=null==T?void 0:T.relationStyles)||void 0===f?void 0:f.low)||{})}}},[T]),$e=t.useMemo(function(){if(E&&Object.keys(E).length>0)try{var n=function(n,t,i){var r,o,l,s;void 0===t&&(t=!1),void 0===i&&(i=null);var c=n.nodes||n,u=[],d=[],v=n.base_root_id,f=n.input_index_map||{0:"left",1:"right"},p=n[v]||c[v];if(!p||!1===p.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var h=function(t,r){var o,l,s,u=n[t]||c[t];if(!u||!1===u.display_node)return null;var d=a.getSideData(u,r,f),v=!1!==(null===(o=d.attributes)||void 0===o?void 0:o.display_title),p=!1!==(null===(l=d.attributes)||void 0===l?void 0:l.display_content),g=!!d.title.trim(),x=!!d.content.trim(),_=a.getRationale(u),m=(null===(s=null==i?void 0:i[t])||void 0===s?void 0:s.evaluation_result)||u.evaluation_result||null,y=[];u.next&&Object.values(u.next).forEach(function(e){var n=c[e];if(n&&!1!==n.display_node){var t=h(e,r);t&&y.push(t)}});var b=!(!g&&!x);return e.__assign(e.__assign({id:t,title:g?d.title:"",content:x?d.content:"",displayTitle:v,displayContent:p,subsections:y},b?_:{score:void 0,relation:"not_defined"}),{evaluationResult:m})};if(t){var g=function(t,r){var o,l,s,u,d,v,p,h,x,_,m,y,b,S,R,C,I,w,F,B,j;void 0===r&&(r=0);var E=[],T=[];if(!t)return{refSections:E,baseSections:T};var A={},M={},k=-1,D=-1;for(var O in t){var N=t[O],H=n[N]||c[N];if(H&&!1!==H.display_node){var L=a.getRationale(H),W=(null===(o=null==i?void 0:i[N])||void 0===o?void 0:o.evaluation_result)||H.evaluation_result||null,z=a.getSideData(H,"1",f),P=a.getSideData(H,"0",f),q=!1!==(null===(l=z.attributes)||void 0===l?void 0:l.display_title)&&z.title.trim()||!1!==(null===(s=z.attributes)||void 0===s?void 0:s.display_content)&&z.content.trim(),Y=!1!==(null===(u=P.attributes)||void 0===u?void 0:u.display_title)&&P.title.trim()||!1!==(null===(d=P.attributes)||void 0===d?void 0:d.display_content)&&P.content.trim(),V=Number(null!==(p=null===(v=z.attributes)||void 0===v?void 0:v.display_index)&&void 0!==p?p:k--),K=Number(null!==(x=null===(h=P.attributes)||void 0===h?void 0:h.display_index)&&void 0!==x?x:D--),U=A[V]||e.__assign(e.__assign({id:N,title:!1!==(null===(_=z.attributes)||void 0===_?void 0:_.display_title)?z.title:"",content:!1!==(null===(m=z.attributes)||void 0===m?void 0:m.display_content)?z.content:"",subsections:[]},q?L:{score:void 0,relation:"not_defined"}),{refIndexes:[],selfIndex:V,evaluationResult:W,displayContent:null===(y=z.attributes)||void 0===y?void 0:y.display_content,displayTitle:null===(b=z.attributes)||void 0===b?void 0:b.display_title}),G=M[K]||e.__assign(e.__assign({id:N,title:!1!==(null===(S=P.attributes)||void 0===S?void 0:S.display_title)?P.title:"",content:!1!==(null===(R=P.attributes)||void 0===R?void 0:R.display_content)?P.content:"",subsections:[]},Y?L:{score:void 0,relation:"not_defined"}),{refIndexes:[],selfIndex:K,evaluationResult:W,displayContent:null===(C=P.attributes)||void 0===C?void 0:C.display_content,displayTitle:null===(I=P.attributes)||void 0===I?void 0:I.display_title});Number(V)>=0&&Number(K)>=0&&((null===(w=U.refIndexes)||void 0===w?void 0:w.includes(Number(K)))||null===(F=U.refIndexes)||void 0===F||F.push(Number(K)),(null===(B=G.refIndexes)||void 0===B?void 0:B.includes(Number(V)))||null===(j=G.refIndexes)||void 0===j||j.push(Number(V))),A[V]=U,M[K]=G;var X=g(H.next,r+1),J=X.refSections,$=X.baseSections;J.length>0&&(U.subsections=e.__spreadArray(e.__spreadArray([],U.subsections||[],!0),J,!0)),$.length>0&&(G.subsections=e.__spreadArray(e.__spreadArray([],G.subsections||[],!0),$,!0))}}return E=Object.values(A).map(function(e){return e}),T=Object.values(M).map(function(e){return e}),E.sort(function(e,n){return e.selfIndex<0&&n.selfIndex>=0?1:e.selfIndex>=0&&n.selfIndex<0?-1:e.selfIndex-n.selfIndex}),T.sort(function(e,n){return e.selfIndex<0&&n.selfIndex>=0?1:e.selfIndex>=0&&n.selfIndex<0?-1:e.selfIndex-n.selfIndex}),{refSections:E,baseSections:T}},x=g(p.next),_=x.refSections,m=x.baseSections;d=_,u=m}else p.next&&Object.values(p.next).forEach(function(e){var t=n[e]||c[e];t&&!1!==t.display_node&&(u.push(h(e,"0")||{id:e,title:"",content:"",subsections:[]}),d.push(h(e,"1")||{id:e,title:"",content:"",subsections:[]}))});return{activeProposed:{title:(null===(o=null===(r=p.comparison_inputs)||void 0===r?void 0:r[f[0]])||void 0===o?void 0:o.title)||"Uploaded Contract",description:p.decision_scope_description||"",sections:u},activeVariants:[{id:"tree-variant-1",title:(null===(s=null===(l=p.comparison_inputs)||void 0===l?void 0:l[f[1]])||void 0===s?void 0:s.title)||"Reference Template",similarity:0,sections:d,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:p.decision_scope_description||""},fields:{}}}}]}}(E,z,L);return e.__assign(e.__assign({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:[],parseError:"Tree data is required"}},[JSON.stringify(E),z,JSON.stringify(L)]),Qe=$e.activeProposed,Ze=$e.activeVariants,en=$e.parseError;t.useEffect(function(){en&&$("Failed to load comparison: ".concat(en))},[en]);var nn=t.useState(null),tn=nn[0];nn[1];var rn=t.useState({}),on=rn[0],ln=rn[1],sn=t.useState({}),an=sn[0],cn=sn[1],un=(null==Ze?void 0:Ze[0])||b,dn=null===(g=null===(f=null==E?void 0:E.documents)||void 0===f?void 0:f[null===(p=null==E?void 0:E.input_index_map)||void 0===p?void 0:p[0]])||void 0===g?void 0:g.title,vn=null===(I=null===(x=null==E?void 0:E.documents)||void 0===x?void 0:x[null===(C=null==E?void 0:E.input_index_map)||void 0===C?void 0:C[1]])||void 0===I?void 0:I.title,fn=a.safeStringify(A||dn||"Uploaded Contract"),pn=a.safeStringify(M||vn||"Reference Template"),hn=t.useMemo(function(){return(null==Qe?void 0:Qe.sections)||[]},[null==Qe?void 0:Qe.sections]),gn=t.useMemo(function(){return un.sections||[]},[un.sections]),xn=hn.length>0||gn.length>0,_n=un.analysis,mn=a.safeStringify(null===(F=null===(w=null==_n?void 0:_n.rule_difference_comparison)||void 0===w?void 0:w.summary)||void 0===F?void 0:F.overall_summary),yn=!!mn.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),bn=t.useRef({}),Sn=function(e){return bn.current[e]||(bn.current[e]=h.default.createRef()),bn.current[e]},Rn=t.useCallback(function(){var e,n,t,i;ee(!1),ye.current=!1;var r=be.current,o=En.current;if(null!==r){var l="string"==typeof r?null===(e=$n.current[r.split(_)[0]])||void 0===e?void 0:e.current:null===(n=Kn.current[r])||void 0===n?void 0:n.current;l&&(l.style.paddingTop="0px")}if(null!==o){var s="string"==typeof o?null===(t=Qn.current[o.split(_)[0]])||void 0===t?void 0:t.current:null===(i=Un.current[o])||void 0===i?void 0:i.current;s&&(s.style.paddingTop="0px")}Ln(null),be.current=null,En.current=null,ie(!1),G(!1),We.current&&(We.current.style.height="0px"),ze.current&&(ze.current.style.height="0px"),Pe.current&&(Pe.current.style.height="0px"),qe.current&&(qe.current.style.height="0px")},[]),Cn=t.useCallback(function(e,n,t,i,r,o){var l,s,c=a.safeStringify(n.id)||a.safeStringify(t.id)||"",u=(c?Se[c]:null)||n.cognitiveData||t.cognitiveData||{section_id:c,decisioning:[],gap:[],relevance_score:0},d=null!==(s=null===(l=bn.current[i])||void 0===l?void 0:l.current)&&void 0!==s?s:null;return{open:!0,sectionTitle:n.title||"N/A",refSectionTitle:t.title||"NA",cognitiveData:u,anchorEl:e,sectionAnchorEl:d,badgeStyle:o||null,sectionIdx:i,docData:{documents:null==E?void 0:E.documents,input_index_map:null==E?void 0:E.input_index_map},deviationData:n.evaluationResult||t.evaluationResult||null,isOrphan:!!r}},[Se,E]),In=t.useCallback(function(e){Ge(),Ie(null),Me(e)},[Ge]),wn=function(e,n,t,i,r,o){e.stopPropagation(),De.open&&De.sectionIdx===r?Ge():(Ue(),Oe(Cn(e.currentTarget,n,i,r,t,o)))},Fn=t.useCallback(function(){null!==De.sectionIdx&&De.anchorEl?In(e.__assign(e.__assign({},De),{open:!0})):Ge()},[De,Ge,In]),Bn=t.useCallback(function(){var e=De.sectionIdx,n=De.isOrphan;Ge(),null!==e&&(n?$("No counterpart exists to connect to."):(ye.current&&Rn(),ue(function(n){return n.has(e)?new Set:new Set([e])})))},[De.sectionIdx,Ge,Rn]),jn=t.useRef(null),En=t.useRef(null),Tn=t.useRef(null),An=t.useRef(null),Mn=t.useRef(null),kn=t.useState([]),Dn=kn[0],On=kn[1],Nn=t.useState(null),Hn=Nn[0],Ln=Nn[1];t.useRef(null);var Wn=t.useState(null),zn=Wn[0],Pn=Wn[1],qn=t.useMemo(function(){return Je.fields.filter(function(e){var n=e.key;return(!xn||"description"!==n)&&(a.hasValue(null==Qe?void 0:Qe[n])||a.hasValue(un[n]))})},[Qe,un,xn,Je.fields]),Yn=t.useRef({}),Vn=t.useRef({}),Kn=t.useRef({}),Un=t.useRef({}),Gn=t.useRef({}),Xn=t.useRef({}),Jn=t.useRef({}),$n=t.useRef({}),Qn=t.useRef({});qn.forEach(function(e){for(var n=e.key,t=0;t<Math.max(hn.length,gn.length);t+=1)Kn.current[t]||(Kn.current[t]=h.default.createRef()),Un.current[t]||(Un.current[t]=h.default.createRef()),Gn.current[t]||(Gn.current[t]=h.default.createRef()),Xn.current[t]||(Xn.current[t]=h.default.createRef()),Jn.current[t]||(Jn.current[t]=h.default.createRef());Yn.current[n]||(Yn.current[n]=h.default.createRef()),Vn.current[n]||(Vn.current[n]=h.default.createRef())});for(var Zn=0;Zn<Math.max(hn.length,gn.length);Zn+=1)Kn.current[Zn]||(Kn.current[Zn]=h.default.createRef()),Un.current[Zn]||(Un.current[Zn]=h.default.createRef()),Gn.current[Zn]||(Gn.current[Zn]=h.default.createRef()),Xn.current[Zn]||(Xn.current[Zn]=h.default.createRef()),Jn.current[Zn]||(Jn.current[Zn]=h.default.createRef());t.useEffect(function(){if(tn){var e=Je.fields.find(function(e){return e.analysisKey===tn||e.key===tn});if(e){var n=Yn.current[e.key]||Vn.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[tn,Je.fields]);var et=t.useCallback(function(e){var n,t,i,r,o,l,s,a,c,u=null===(n=null==_n?void 0:_n.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!u||!u[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var d=u[e],v=(null==d?void 0:d.relation)||(null===(i=null===(t=null==d?void 0:d.highlights)||void 0===t?void 0:t.ruleA_spans)||void 0===i?void 0:i.length)||(null===(o=null===(r=null==d?void 0:d.highlights)||void 0===r?void 0:r.ruleB_spans)||void 0===o?void 0:o.length)||(null==d?void 0:d.mappings)&&d.mappings.length>0;if(d.mappings){var f=d.mappings[0]||{};return{score:d.score,relation:f.relation||"",highlightsA:(null===(l=f.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(s=f.highlights)||void 0===s?void 0:s.ruleB_spans)||[],hasContent:!!v}}return{score:d.score,relation:d.relation||"",highlightsA:(null===(a=d.highlights)||void 0===a?void 0:a.ruleA_spans)||[],highlightsB:(null===(c=d.highlights)||void 0===c?void 0:c.ruleB_spans)||[],hasContent:!!v}},[_n]),nt=t.useCallback(function(n){var t,i,r,o=hn[n],l=gn[n],s=(null==o?void 0:o.relation)&&"not_defined"!==o.relation,c=(null==l?void 0:l.relation)&&"not_defined"!==l.relation;a.safeStringify(null==o?void 0:o.id)||a.safeStringify(null==l?void 0:l.id);var u=!(!(null==o?void 0:o.cognitiveData)&&!(null==l?void 0:l.cognitiveData));if(!s&&!c&&!u)return e.__assign(e.__assign({},Je.relationStyles.noContent),{label:"Not Defined"});var d=null!==(i=null!==(t=null==o?void 0:o.evaluationResult)&&void 0!==t?t:null==l?void 0:l.evaluationResult)&&void 0!==i?i:null,v=null===(r=null==d?void 0:d.evaluation_outputs)||void 0===r?void 0:r.output_value;return null!=d?e.__assign(e.__assign({},Je.relationStyles.low),{label:null!=v?v:""}):e.__assign(e.__assign({},Je.relationStyles.low),{label:"N/A"})},[hn,gn,Se,Je,et]),tt=t.useCallback(function(n){for(var t,i,r,o,l,s,c=n.split("-").map(Number),u=hn[c[0]],d=gn[c[0]],v=1;v<c.length;v++)(null==u?void 0:u.subsections)&&(u=u.subsections[c[v]]),(null==d?void 0:d.subsections)&&(d=d.subsections[c[v]]);if(!u&&!d)return null;var f=(null==u?void 0:u.relation)&&"not_defined"!==u.relation,p=(null==d?void 0:d.relation)&&"not_defined"!==d.relation,h=a.safeStringify(null==u?void 0:u.id)||a.safeStringify(null==d?void 0:d.id)||"",g=!(!(null==u?void 0:u.cognitiveData)&&!(null==d?void 0:d.cognitiveData));if(!f&&!p&&!g)return e.__assign(e.__assign({},Je.relationStyles.noContent),{label:"Not Defined"});null!==(i=null!==(t=null==u?void 0:u.cognitiveRelevanceScore)&&void 0!==t?t:null==d?void 0:d.cognitiveRelevanceScore)&&void 0!==i||h&&(null===(r=Se[h])||void 0===r||r.relevance_score);var x=null!==(l=null!==(o=null==u?void 0:u.evaluationResult)&&void 0!==o?o:null==d?void 0:d.evaluationResult)&&void 0!==l?l:null,_=null===(s=null==x?void 0:x.evaluation_outputs)||void 0===s?void 0:s.output_value;return null!=x?e.__assign(e.__assign({},Je.relationStyles.low),{label:null!=_?_:""}):e.__assign(e.__assign({},Je.relationStyles.low),{label:"N/A"})},[hn,gn,Se,Je]),it=t.useCallback(function(){var e,n,t,i,r,o,l,s,a,c,u,d,v,f,p,h,g,x,m,b,S,R;if(!Ve.current&&!he.current){Ve.current=!0;try{if(!jn.current)return;var C=function(e){var n=e.split("-"),t=n[0];if(!on[t]&&!1===z)return!1;if(z&&!on["left-".concat(t)]&&!on["right-".concat(t)]&&!on[t])return!1;for(var i=t,r=1;r<n.length-1;r++)if(i+="-".concat(n[r]),!an[i])return!1;return!0},I=jn.current.getBoundingClientRect();je({width:I.width,height:I.height});var w=[];if(qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;r&&o&&(r.style.height="auto",o.style.height="auto",r.style.minHeight="0px",o.style.minHeight="0px")}),!he.current){for(var F=0;F<Math.max(hn.length,gn.length);F++){var B=null===(e=Kn.current[F])||void 0===e?void 0:e.current,j=null===(n=Un.current[F])||void 0===n?void 0:n.current;B&&(B.style.height="auto",B.style.minHeight="0px"),j&&(j.style.height="auto",j.style.minHeight="0px")}z||Object.keys($n.current).forEach(function(e){var n,t;if(C(e)){var i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;i&&r&&(i.style.height="auto",r.style.height="auto",i.style.minHeight="0px",r.style.minHeight="0px")}})}var E={};qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;if(r&&o){var l=r.getBoundingClientRect(),s=o.getBoundingClientRect();E[i]=Math.max(l.height,s.height)}});var T={left:{},right:{}},A={};if(!he.current)if(z){if(Z&&null!==Hn)if("number"==typeof Hn){var M=Hn,k=hn[M],D=null===(r=Kn.current[M])||void 0===r?void 0:r.current;D&&k&&(k.refIndexes||[]).forEach(function(e){var n,t=gn.findIndex(function(n){return n.selfIndex===e}),i=null===(n=Un.current[t])||void 0===n?void 0:n.current;if(i&&(on["left-".concat(M)]||on["right-".concat(t)])){var r=Math.max(D.getBoundingClientRect().height,i.getBoundingClientRect().height);T.left[M]=Math.max(T.left[M]||0,r),T.right[t]=Math.max(T.right[t]||0,r)}})}else{var O=Hn.split(_)[0];B=null===(o=$n.current[O])||void 0===o?void 0:o.current,j=null===(l=Qn.current[O])||void 0===l?void 0:l.current;if(B&&j){N=Math.max(B.getBoundingClientRect().height,j.getBoundingClientRect().height);A[O]=Math.max(A[O]||0,N)}}}else{Object.keys($n.current).forEach(function(e){var n,t;if(C(e)){var i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;if(i&&r&&null!==i.offsetParent&&null!==r.offsetParent){var o=i.getBoundingClientRect(),l=r.getBoundingClientRect(),s=Math.max(o.height,l.height);A[e]=s,i.style.minHeight="".concat(s,"px"),r.style.minHeight="".concat(s,"px")}}});for(F=0;F<Math.min(hn.length,gn.length);F++){var B=null===(t=Kn.current[F])||void 0===t?void 0:t.current,j=null===(i=Un.current[F])||void 0===i?void 0:i.current;if(B&&j){var N=Math.max(B.getBoundingClientRect().height,j.getBoundingClientRect().height);T.left[F]=N,T.right[F]=N}}}if(qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;if(r&&o){var l=E[i];r.style.minHeight="".concat(l,"px"),o.style.minHeight="".concat(l,"px")}}),he.current||(Object.entries(T.left).forEach(function(e){var n,t=e[0],i=e[1],r=null===(n=Kn.current[Number(t)])||void 0===n?void 0:n.current;r&&(r.style.minHeight="".concat(i,"px"))}),Object.entries(T.right).forEach(function(e){var n,t=e[0],i=e[1],r=null===(n=Un.current[Number(t)])||void 0===n?void 0:n.current;r&&(r.style.minHeight="".concat(i,"px"))}),z||Object.keys(A).forEach(function(e){var n,t,i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;if(i&&r&&A[e]){var o=A[e];i.style.minHeight="".concat(o,"px"),r.style.minHeight="".concat(o,"px")}})),z)hn.forEach(function(e,n){var t;(null===(t=Kn.current[n])||void 0===t?void 0:t.current)&&(e.refIndexes||[]).forEach(function(e){var t,i,r,o,l,s,a,c,u,d,v=gn.findIndex(function(n){return n.selfIndex===e});if(-1!==v){var f=null===(t=Gn.current[n])||void 0===t?void 0:t.current,p=null===(i=Xn.current[v])||void 0===i?void 0:i.current;if(f&&p){var h=f.getBoundingClientRect(),g=p.getBoundingClientRect(),x=h.right-I.left,_=g.left-I.left,m=h.top+h.height/2-I.top,y=g.top+g.height/2-I.top;if(Z&&Hn===n){var b=null!==(o=null===(r=Ye.current)||void 0===r?void 0:r.getBoundingClientRect().top)&&void 0!==o?o:0,S=null!==(s=null===(l=Le.current)||void 0===l?void 0:l.getBoundingClientRect().top)&&void 0!==s?s:0,R=b+(null!==(c=null===(a=Ye.current)||void 0===a?void 0:a.clientHeight)&&void 0!==c?c:1/0),C=S+(null!==(d=null===(u=Le.current)||void 0===u?void 0:u.clientHeight)&&void 0!==d?d:1/0),F=h.top+h.height/2,B=function(e,n,t){return Math.max(n,Math.min(t,e))};m=B(F,b,R)-I.top,y=B(F,S,C)-I.top}var j=nt(n);j&&w.push({id:"line-".concat(n,"-").concat(v),x1:x,y1:m,x2:_,y2:y,style:j,sectionIdx:n,targetRightIdx:v})}}})});else for(F=0;F<Math.min(hn.length,gn.length);F++){var H=null===(s=Kn.current[F])||void 0===s?void 0:s.current,L=null===(a=Un.current[F])||void 0===a?void 0:a.current;if(H&&L){var W=H.getBoundingClientRect(),P=L.getBoundingClientRect(),q=Math.max(W.top,P.top)+18-I.top,Y=(null===(c=gn[F])||void 0===c?void 0:c.id)||"sec-".concat(F);(G=nt(F))&&w.push({id:Y,x1:W.right-I.left,y1:q,x2:P.left-I.left,y2:q,style:G,sectionIdx:F,hasCognitive:!!((null===(u=hn[F])||void 0===u?void 0:u.cognitiveData)||(null===(d=gn[F])||void 0===d?void 0:d.cognitiveData)||Y&&Se[Y]),isSubSection:!1})}}if(Z&&"string"==typeof Hn){var V=Hn,K=(O=V.split(_)[0],null===(v=Gn.current[V])||void 0===v?void 0:v.current),U=null===(f=Xn.current[V])||void 0===f?void 0:f.current;if(K&&U){var G,X=K.getBoundingClientRect(),J=U.getBoundingClientRect(),$=X.right-I.left,Q=J.left-I.left,ee=X.top+X.height/2-I.top,ne=J.top+J.height/2-I.top;if(z){var te=null!==(h=null===(p=Ye.current)||void 0===p?void 0:p.getBoundingClientRect().top)&&void 0!==h?h:0,ie=null!==(x=null===(g=Le.current)||void 0===g?void 0:g.getBoundingClientRect().top)&&void 0!==x?x:0,re=te+(null!==(b=null===(m=Ye.current)||void 0===m?void 0:m.clientHeight)&&void 0!==b?b:1/0),oe=ie+(null!==(R=null===(S=Le.current)||void 0===S?void 0:S.clientHeight)&&void 0!==R?R:1/0),le=function(e,n,t){return Math.max(n,Math.min(t,e))};ee=le(X.top+X.height/2,te,re)-I.top,ne=le(J.top+J.height/2,ie,oe)-I.top}(G=tt(O))&&w.push({id:"line-subsec-".concat(V),x1:$,y1:ee,x2:Q,y2:ne,style:G,sectionIdx:Number(O.split("-")[0]),isSubSection:!0,subSectionKeyPath:V})}}if(On(w),An.current&&Mn.current){var se=An.current.getBoundingClientRect(),ae=Mn.current.getBoundingClientRect(),ue=(se.top+se.height/2-I.top+ae.top+ae.height/2-I.top)/2;Pn({x1:se.right-I.left,x2:ae.left-I.left,y:ue})}else Pn(null);if(ce.size>0){var de=[],ve=Ye.current,pe=Le.current;if(ve&&pe){var ge=[],xe=ve.getBoundingClientRect().top,me=pe.getBoundingClientRect().top,ye=xe+ve.clientHeight,be=me+pe.clientHeight,Re=ve.scrollTop,Ce=pe.scrollTop,Ie=I.top,we=function(e,n,t){return Math.max(n,Math.min(t,e))};ce.forEach(function(e){var n,t,i,r,o;if("string"==typeof e){var l=e,s=l.split(_)[0],a=null===(n=Gn.current[l])||void 0===n?void 0:n.current,c=null===(t=Xn.current[l])||void 0===t?void 0:t.current;if(!a||!c)return;var u=a.getBoundingClientRect(),d=c.getBoundingClientRect(),v=tt(s),f=(E=u.right-I.left)+.5*((T=d.left-I.left-0)-E),p=u.top+u.height/2,h=d.top+d.height/2,g=p-xe+Re,x=h-me+Ce,m="conn-subsec-".concat(l);ge.push({lhsScrollY:g,rhsScrollY:x,x1:E,x2:T,containerTop:Ie,leftIdx:l,rhsArrayIdx:l,styleColor:(null==v?void 0:v.badgeBorder)||"#6366F1",styleId:m});var b=we(p,xe,ye),S=we(h,me,be),R=b-Ie,C=S-Ie,w=h>=me-4&&h<=be+4,F="";F=(A=p>=xe-4&&p<=ye+4)&&w?y(E,R,T,C):A&&!w?"M ".concat(E,",").concat(R," L ").concat(f,",").concat(R," L ").concat(f,",").concat(C):!A&&w?"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C," L ").concat(T,",").concat(C):"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C),de.push({id:m,pathD:F,style:v,leftIdx:l,rhsArrayIdx:l})}else if(z){var B=hn[e];if(!(null===(o=null==B?void 0:B.refIndexes)||void 0===o?void 0:o.length))return;B.refIndexes.forEach(function(n){var t,i,r=gn.findIndex(function(e){return e.selfIndex===n});if(-1!==r){var o=null===(t=Gn.current[e])||void 0===t?void 0:t.current,l=null===(i=Xn.current[r])||void 0===i?void 0:i.current;if(o&&l){var s=o.getBoundingClientRect(),a=l.getBoundingClientRect(),c=nt(e),u=s.right-I.left,d=a.left-I.left-0,v=u+.5*(d-u),f=s.top+s.height/2,p=a.top+a.height/2,h=f-xe+Re,g=p-me+Ce,x="conn-".concat(e,"-").concat(r);ge.push({lhsScrollY:h,rhsScrollY:g,x1:u,x2:d,containerTop:Ie,leftIdx:e,rhsArrayIdx:r,styleColor:(null==c?void 0:c.badgeBorder)||"#6366F1",styleId:x});var _=we(f,xe,ye),m=we(p,me,be),b=_-Ie,S=m-Ie,R=f>=xe-4&&f<=ye+4,C=p>=me-4&&p<=be+4,w="";w=R&&C?y(u,b,d,S):R&&!C?"M ".concat(u,",").concat(b," L ").concat(v,",").concat(b," L ").concat(v,",").concat(S):!R&&C?"M ".concat(v,",").concat(b," L ").concat(v,",").concat(S," L ").concat(d,",").concat(S):"M ".concat(v,",").concat(b," L ").concat(v,",").concat(S),de.push({id:x,pathD:w,style:c,leftIdx:e,rhsArrayIdx:r})}}})}else{var j=e;a=null===(i=Gn.current[e])||void 0===i?void 0:i.current,c=null===(r=Xn.current[j])||void 0===r?void 0:r.current;if(!a||!c)return;var E,T;u=a.getBoundingClientRect(),d=c.getBoundingClientRect(),v=nt(e),f=(E=u.right-I.left)+.5*((T=d.left-I.left-0)-E),p=u.top+u.height/2,h=d.top+d.height/2,g=p-xe+Re,x=h-me+Ce,m="conn-".concat(e,"-").concat(j);ge.push({lhsScrollY:g,rhsScrollY:x,x1:E,x2:T,containerTop:Ie,leftIdx:e,rhsArrayIdx:j,styleColor:(null==v?void 0:v.badgeBorder)||"#6366F1",styleId:m});var A;b=we(p,xe,ye),S=we(h,me,be),R=b-Ie,C=S-Ie,w=h>=me-4&&h<=be+4,F="";F=(A=p>=xe-4&&p<=ye+4)&&w?y(E,R,T,C):A&&!w?"M ".concat(E,",").concat(R," L ").concat(f,",").concat(R," L ").concat(f,",").concat(C):!A&&w?"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C," L ").concat(T,",").concat(C):"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C),de.push({id:m,pathD:F,style:v,leftIdx:e,rhsArrayIdx:j})}}),_e.current=ge}fe(de)}else fe([]),_e.current=[]}catch(e){console.error("Line render safe fail: ",e)}finally{Ve.current=!1}}},[qn,hn,gn,Se,Je,et,nt,z,Z,Hn,ce,on,an]),rt=t.useCallback(function(){var e,n,t,i,r,o,l,s,a,c,u,d,v,f,p=_e.current;if(p.length&&!he.current){var h=null!==(n=null===(e=Ye.current)||void 0===e?void 0:e.scrollTop)&&void 0!==n?n:0,g=null!==(i=null===(t=Le.current)||void 0===t?void 0:t.scrollTop)&&void 0!==i?i:0,x=null!==(o=null===(r=Ye.current)||void 0===r?void 0:r.clientHeight)&&void 0!==o?o:1/0,_=null!==(s=null===(l=Le.current)||void 0===l?void 0:l.clientHeight)&&void 0!==s?s:1/0,m=null!==(c=null===(a=Ye.current)||void 0===a?void 0:a.getBoundingClientRect().top)&&void 0!==c?c:0,b=null!==(d=null===(u=Le.current)||void 0===u?void 0:u.getBoundingClientRect().top)&&void 0!==d?d:0,S=m+x,R=b+_,C=null!==(f=null===(v=jn.current)||void 0===v?void 0:v.getBoundingClientRect().top)&&void 0!==f?f:0,I=function(e,n,t){return Math.max(n,Math.min(t,e))};p.forEach(function(e){var n=e.lhsScrollY-h+m,t=e.rhsScrollY-g+b,i=xe.current[e.styleId+"-stroke"],r=xe.current[e.styleId+"-bg"];if(i||r){var o,l=I(n,m,S),s=I(t,b,R),a=l-C,c=s-C,u=n>=m-4&&n<=S+4,d=t>=b-4&&t<=R+4,v=e.x1+.5*(e.x2-e.x1);o=u&&d?y(e.x1,a,e.x2,c):u&&!d?"M ".concat(e.x1,",").concat(a," L ").concat(v,",").concat(a," L ").concat(v,",").concat(c):!u&&d?"M ".concat(v,",").concat(a," L ").concat(v,",").concat(c," L ").concat(e.x2,",").concat(c):"M ".concat(v,",").concat(a," L ").concat(v,",").concat(c),i&&(i.setAttribute("visibility","visible"),i.setAttribute("d",o)),r&&(r.setAttribute("visibility","visible"),r.setAttribute("d",o))}})}},[]),ot=t.useRef(it);t.useEffect(function(){ot.current=it},[it]);var lt=t.useRef(null),st=t.useCallback(function(){null!==lt.current&&clearTimeout(lt.current),lt.current=setTimeout(function(){ot.current(),lt.current=null},50)},[]),at=t.useCallback(function(e){var n,t,i,r,o,l,s,a;if(!re.current){if(z||st(),ye.current){var c=be.current,u=En.current,d=Ye.current,v=Le.current;if(null!==c&&null!==u&&d&&v){var f="string"==typeof c?null===(n=Gn.current[c])||void 0===n?void 0:n.current:null===(t=bn.current[c])||void 0===t?void 0:t.current,p="string"==typeof u?null===(i=Xn.current[u])||void 0===i?void 0:i.current:null===(r=Jn.current[u])||void 0===r?void 0:r.current;if(f&&p){var h=f.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop,g=p.getBoundingClientRect().top-v.getBoundingClientRect().top+v.scrollTop;if(e.currentTarget===d){var x=g-(h-d.scrollTop),_=v.scrollHeight-v.clientHeight,m=Math.max(0,Math.min(x,_));Math.abs(v.scrollTop-m)>1&&(v.scrollTop=m)}else if(e.currentTarget===v){var y=h-(g-v.scrollTop),b=d.scrollHeight-d.clientHeight,S=Math.max(0,Math.min(y,b));Math.abs(d.scrollTop-S)>1&&(d.scrollTop=S)}if(Tn.current){var R=null===(o=Gn.current[c])||void 0===o?void 0:o.current,C=null===(l=Xn.current[u])||void 0===l?void 0:l.current,I=null!==(a=null===(s=jn.current)||void 0===s?void 0:s.getBoundingClientRect().top)&&void 0!==a?a:0,w=d.getBoundingClientRect().top,F=w+d.clientHeight,B=v.getBoundingClientRect().top,j=B+v.clientHeight,E=function(e,n,t){return Math.max(n,Math.min(t,e))};if(R&&C){var T=R.getBoundingClientRect(),A=C.getBoundingClientRect(),M=T.top+T.height/2,k=A.top+A.height/2,D=E(M,w,F),O=E(k,B,j);Tn.current.setAttribute("y1",(D-I).toString()),Tn.current.setAttribute("y2",(O-I).toString());var N=M>=w-4&&M<=F+4;Tn.current.setAttribute("visibility",N?"visible":"hidden")}}}}}_e.current.length>0&&!me.current&&(me.current=!0,requestAnimationFrame(function(){rt(),me.current=!1}))}},[rt,z,st]);t.useEffect(function(){var e=setTimeout(st,250);window.addEventListener("resize",st);var n=null,t=null;return Ne.current&&(n=new ResizeObserver(st)).observe(Ne.current),jn.current&&(t=new ResizeObserver(st)).observe(jn.current),function(){clearTimeout(e),window.removeEventListener("resize",st),null==n||n.disconnect(),null==t||t.disconnect()}},[Qe,un,_n,qn,on,an,hn,gn,Je,st,Z,Hn,te,ce]),t.useEffect(function(){ye.current=Z},[Z]),t.useEffect(function(){be.current=Hn},[Hn]);var ct=t.useCallback(function(){var e,n,t,i,r=De.sectionIdx,o=De.isOrphan;if(Ge(),null!=r)if(o)$("No counterpart exists for this section.");else if(Z&&Hn===r)Rn();else{if(!z){var l=be.current,s=En.current;if(null!==l){var a="string"==typeof l?null===(e=$n.current[l.split(_)[0]])||void 0===e?void 0:e.current:null===(n=Kn.current[l])||void 0===n?void 0:n.current;a&&(a.style.paddingTop="0px")}if(null!==s){var c="string"==typeof s?null===(t=Qn.current[s.split(_)[0]])||void 0===t?void 0:t.current:null===(i=Un.current[s])||void 0===i?void 0:i.current;c&&(c.style.paddingTop="0px")}}ue(new Set),fe([]),_e.current=[],G(!0),re.current=!0,Ln(r),be.current=r,ee(!0),ye.current=!0,ie(!1),We.current&&(We.current.style.height="0px"),ze.current&&(ze.current.style.height="0px"),Pe.current&&(Pe.current.style.height="0px"),qe.current&&(qe.current.style.height="0px"),requestAnimationFrame(function(){var e,n,t,i,o,l,s,a,c,u,d,v=null,f=null,p=null,h=null,g=null;if("string"==typeof r){v=(null===(e=Gn.current[r])||void 0===e?void 0:e.current)||null,g=(f=(null===(n=Xn.current[r])||void 0===n?void 0:n.current)||null)?r:null;var x=r.split(_)[0];p=(null===(t=$n.current[x])||void 0===t?void 0:t.current)||null,h=(null===(i=Qn.current[x])||void 0===i?void 0:i.current)||null}else if(v=(null===(o=bn.current[r])||void 0===o?void 0:o.current)||null,p=(null===(l=Kn.current[r])||void 0===l?void 0:l.current)||null,z){var m=hn[r],y=(null==m?void 0:m.refIndexes)||[];if(y.length>0){var b=y[0],S=gn.findIndex(function(e){return e.selfIndex===b});-1!==S&&(f=(null===(c=Jn.current[S])||void 0===c?void 0:c.current)||null,h=(null===(u=Un.current[S])||void 0===u?void 0:u.current)||null,g=S)}}else f=(null===(s=Jn.current[r])||void 0===s?void 0:s.current)||null,h=(null===(a=Un.current[r])||void 0===a?void 0:a.current)||null,g=f?r:null;En.current=g;var C=Ye.current,I=Le.current;if(!v||!C)return re.current=!1,void G(!1);if(!f||!I)return ie(!0),ot.current(),re.current=!1,void G(!1);if(!z){var w=v.getBoundingClientRect(),F=f.getBoundingClientRect(),B=w.top-F.top;p&&h&&(p.style.paddingTop="0px",h.style.paddingTop="0px",B>0?h.style.paddingTop="".concat(B,"px"):B<0&&(p.style.paddingTop="".concat(Math.abs(B),"px")));var j=v?v.getBoundingClientRect().top:(null==p?void 0:p.getBoundingClientRect().top)||0;return null===(d=Ne.current)||void 0===d||d.scrollTo({top:Ne.current.scrollTop+j-150,behavior:"smooth"}),ie(!0),ot.current(),re.current=!1,void G(!1)}var E=v.getBoundingClientRect().top-C.getBoundingClientRect().top+C.scrollTop,T=f.getBoundingClientRect().top-I.getBoundingClientRect().top+I.scrollTop-(E-C.scrollTop);T<0&&We.current&&(We.current.style.height="".concat(Math.abs(T),"px"));requestAnimationFrame(function(){var e,n=I.scrollHeight-I.clientHeight;if(T<0)e=0;else{if(T>n){var t=T-n;return ze.current&&(ze.current.style.height="".concat(t+150,"px")),void requestAnimationFrame(function(){R(I,T,200,function(){ie(!0),ot.current(),re.current=!1,G(!1)})})}e=T}R(I,e,200,function(){ie(!0),ot.current(),re.current=!1,G(!1)})})})}},[Ge,De.sectionIdx,Z,Hn,hn,gn,st,Rn]),ut=null!==De.sectionIdx&&ce.has(De.sectionIdx),dt=function(t){var o,l,s,c=t.section,u=t.idx,d=t.columnKey,v=t.colRef,f=t.mb,p=void 0===f?1:f,g=t.parentNodeId,x=void 0===g?"":g,_=z?!!on["".concat(d,"-").concat(u)]:!!on[String(u)],y=(null===(o=c.displayTitle)||void 0===o||o)&&a.hasValue(c.title),b=(null===(l=c.displayContent)||void 0===l||l)&&a.hasValue(c.content),S=!y&&!b,R={current:1},C=c.title;y||(C=b?"No Title Found":"No Matching Section Found");var I,w=[];if(null===(s=c.evaluationResult)||void 0===s?void 0:s.deviations){var F=c.evaluationResult.deviations;for(var B in F){var j=F[B][x];j&&w.push(j)}}return n.jsx(i.Box,e.__assign({ref:v,sx:{mb:p,width:"100%",display:"flex",flexDirection:"column",position:"relative",minWidth:0}},{children:n.jsxs(i.Accordion,e.__assign({disableGutters:!0,expanded:!S&&_,onChange:function(){return!S&&function(n,t){var i,r;he.current=!0,ge.current&&clearTimeout(ge.current),pe.current&&(pe.current.style.opacity="0");var o=null===(i=Kn.current[n])||void 0===i?void 0:i.current,l=null===(r=Un.current[n])||void 0===r?void 0:r.current;o&&(o.style.minHeight="0px"),l&&(l.style.minHeight="0px"),ge.current=setTimeout(function(){he.current=!1,ot.current(),pe.current&&(pe.current.style.opacity="1")},650),ln(function(i){var r=e.__assign({},i),o=z?"".concat(t,"-").concat(n):String(n),l=!i[o];if(!l){var s=String(Hn||""),a=Hn===n||s.startsWith("".concat(n,"-")),c=!1;ce.forEach(function(e){(e===n||String(e).startsWith("".concat(n,"-")))&&(c=!0)}),(a||c)&&(Rn(),ue(new Set),fe([]),_e.current=[])}if(!z)return r[String(n)]=l,r;if(r[o]=l,"left"===t)((null==(u=hn[n])?void 0:u.refIndexes)||[]).forEach(function(e){var n=gn.findIndex(function(n){return n.selfIndex===e});-1!==n&&(r["right-".concat(n)]=l)});else{var u,d=null==(u=gn[n])?void 0:u.selfIndex;hn.forEach(function(e,n){var t;(null===(t=e.refIndexes)||void 0===t?void 0:t.includes(d))&&(r["left-".concat(n)]=l)})}return r})}(u,d)},sx:{boxShadow:"none",border:S?"1px dashed #E2E8F0":"1px solid #E2E8F0",bgcolor:S?"#FAFAFA":"#FFFFFF",borderRadius:"6px",flexGrow:1,width:"100%",display:"flex",flexDirection:"column",minWidth:0,"&:before":{display:"none"}}},{children:[n.jsx(i.AccordionSummary,e.__assign({expandIcon:S?null:n.jsx(r.ChevronDown,{size:16}),sx:{minHeight:"36px",flexShrink:0,cursor:S?"default":"pointer","& .MuiAccordionSummary-content":{my:.5,display:"grid",alignItems:"center",minWidth:0,width:"100%"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:y&&n.jsx(i.Tooltip,e.__assign({title:C,placement:"top"},{children:n.jsx(i.Typography,e.__assign({component:"div",sx:{fontSize:"12px",color:S?"#94A3B8":"#19213D",fontWeight:S?400:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0}},{children:(I=C,I?a.safeStringify(I).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,t){return e.startsWith("**")&&e.endsWith("**")?n.jsx("strong",{children:e.slice(2,-2)},t):n.jsx(h.default.Fragment,{children:e},t)}):null)}))}))})),!S&&n.jsxs(i.AccordionDetails,e.__assign({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column",minWidth:0}},{children:[b&&n.jsx(m,{content:c.content,sxStyles:Ee,highlights:w,maintainRelativeOrder:z}),(c.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(u,"-").concat(n),depth:0,columnKey:d,parentNodeId:x,devCounter:R})})]}))]}))}),"".concat(d,"-sec-").concat(u))},vt=function(t){var o,l,s,c,u,d,v,f,p,g=t.section,x=t.keyPath,y=t.depth,b=void 0===y?0:y,S=t.columnKey,R=void 0===S?"left":S,C=t.parentNodeId,I=void 0===C?"":C,w=t.devCounter,F=void 0===w?{current:1}:w,B=(null===(o=g.displayTitle)||void 0===o||o)&&a.hasValue(g.title),j=(null===(l=g.displayContent)||void 0===l||l)&&a.hasValue(g.content),T=!B&&!j,A=B?g.title:j?"No Title Found":"No Matching Section Found",M=!!an[x];"left"!==R||$n.current[x]||($n.current[x]=h.default.createRef()),"right"!==R||Qn.current[x]||(Qn.current[x]=h.default.createRef());var k,D="left"===R?$n.current[x]:Qn.current[x],O=tt(x),N=x.split("-").map(Number),H=hn[N[0]];k=z&&void 0!==(null==H?void 0:H.selfIndex)&&H.selfIndex>=0?H.selfIndex+1:N[0]+1;for(var L=hn[N[0]],W=gn[N[0]],P=1;P<N.length;P++)(null==L?void 0:L.subsections)&&(L=L.subsections[N[P]]),(null==W?void 0:W.subsections)&&(W=W.subsections[N[P]]);var q=null===(s=null==E?void 0:E.input_index_map)||void 0===s?void 0:s[0],Y=null===(c=null==E?void 0:E.input_index_map)||void 0===c?void 0:c[1],V="left"===R?Y:q,K=z?!(null===(u=g.refIndexes)||void 0===u?void 0:u.length)||void 0!==g.selfIndex&&g.selfIndex<0:"left"===R?!W:!L,U=null!==(f=null===(v=null===(d=g.evaluationResult)||void 0===d?void 0:d.evaluation_outputs)||void 0===v?void 0:v.output_value)&&void 0!==f?f:null,G=Object.entries((null===(p=g.evaluationResult)||void 0===p?void 0:p.deviations)||{}).map(function(e){var n=e[0],t=e[1],i=F.current++,r=t[I],o="No equivalent clause present."===r;if(o)r="";else if(!r)return null;var l=function(e,n){return"".concat(e).concat(_).concat(n)}(x,n),s=t[V],a=K||!s||"No equivalent clause present."===s,c="".concat(k,".").concat(i);return"left"!==R||Gn.current[l]||(Gn.current[l]=h.default.createRef()),"right"!==R||Xn.current[l]||(Xn.current[l]=h.default.createRef()),{id:l,label:c,highlight:r,side:R,style:O,score:U,isConnected:ce.has(l),isOrphan:a,isMissingClause:o,badgeRef:"left"===R?Gn.current[l]:Xn.current[l],onClick:function(e){e.stopPropagation(),wn(e,L||{title:"",content:""},a,W||{title:"",content:""},l,O)}}}).filter(Boolean),X=G.some(function(e){return ce.has(e.id)});return B||j||g.subsections&&0!==g.subsections.length?B?n.jsx(i.Box,e.__assign({ref:D,sx:{mt:1,width:"100%",minWidth:0,position:"relative"}},{children:n.jsx(i.Box,e.__assign({sx:e.__assign({width:"100%"},X&&O&&{borderRadius:"4px",outline:"2px solid ".concat(O.badgeBorder),outlineOffset:"1px"})},{children:n.jsxs(i.Accordion,e.__assign({disableGutters:!0,expanded:!T&&M,onChange:function(){if(!T){if(M){var n=String(Hn||"").startsWith(x);n||ce.forEach(function(e){String(e).startsWith(x)&&(n=!0)}),n&&(Rn(),ue(new Set),fe([]),_e.current=[])}cn(function(n){var t;return e.__assign(e.__assign({},n),((t={})[x]=!n[x],t))})}},sx:{mt:0,boxShadow:"none",border:T?"1px dashed #E2E8F0":"1px solid #EEF2F7",borderRadius:"4px !important",bgcolor:"#FFFFFF",minWidth:0,"&:before":{display:"none"}}},{children:[n.jsx(i.AccordionSummary,e.__assign({expandIcon:T?null:n.jsx(r.ChevronDown,{size:14}),sx:{minHeight:"32px","& .MuiAccordionSummary-content":{my:.5,display:"grid",alignItems:"center",minWidth:0,width:"100%"}}},{children:n.jsx(i.Typography,e.__assign({component:"div",sx:{fontSize:"11px",fontWeight:600,color:T?"#94A3B8":"#19213D",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0}},{children:A||"Untitled Subsection"}))})),!T&&n.jsxs(i.AccordionDetails,e.__assign({sx:{pt:0,pb:1,minWidth:0}},{children:[j&&n.jsx(m,{content:g.content,sxStyles:Ee,deviationBadges:G,maintainRelativeOrder:z}),(g.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(x,"-").concat(n),depth:b+1,columnKey:R,parentNodeId:I,devCounter:F})})]}))]}))}))}),x):n.jsx(i.Box,e.__assign({ref:D,sx:{mt:0===b?1:.75,width:"100%",minWidth:0,position:"relative"}},{children:!T&&n.jsxs(i.Box,e.__assign({sx:e.__assign({width:"100%"},X&&O&&{borderRadius:"4px",outline:"2px solid ".concat(O.badgeBorder),outlineOffset:"1px"})},{children:[j&&n.jsx(m,{content:g.content,sxStyles:Ee,deviationBadges:G,maintainRelativeOrder:z}),(g.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(x,"-").concat(n),depth:b+1,columnKey:R,parentNodeId:I,devCounter:F})})]}))}),x):null};return n.jsxs(i.Box,e.__assign({ref:He,sx:e.__assign(e.__assign({display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif'},z?{}:{overflow:"visible"}),{position:"relative"})},{children:[Y&&n.jsx(i.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(v.default,{})})),n.jsx(d.default,{open:De.open,anchorEl:De.anchorEl,sectionTitle:De.sectionTitle,referenceSectionTitle:De.refSectionTitle,onClose:Ge,onOpenCognitiveCompare:Fn,onOpenSideBySide:ct,onConnect:Bn,isConnected:ut,isOrphan:De.isOrphan}),Ae.open&&n.jsx(u.default,{open:Ae.open,popupRef:we,position:Ce,popupConfig:N,onClose:function(){Ie(null),Me(function(n){return e.__assign(e.__assign({},n),{open:!1})}),se(null)},markdownStyles:k,sectionTitle:Ae.sectionTitle,referenceSectionTitle:Ae.refSectionTitle,cognitiveData:Ae.cognitiveData,anchorEl:Ae.anchorEl,sectionAnchorEl:Ae.sectionAnchorEl,scrollContainerEl:Ne.current,badgeStyle:Ae.badgeStyle,docData:Ae.docData,deviationData:Ae.deviationData}),n.jsx(i.Snackbar,e.__assign({open:!!J,autoHideDuration:8e3,onClose:function(){return $(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(i.Alert,e.__assign({onClose:function(){return $(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:J}))})),(O.isHeaderVisible||O.isToggleVisible)&&n.jsxs(i.Box,e.__assign({sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:"#FFFFFF",border:"1.5px solid #EEF0F4",borderTopLeftRadius:"8px",borderTopRightRadius:"8px"}},{children:[n.jsx(i.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1}},{children:O.isHeaderVisible&&n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:600,color:"#0F172A"}},{children:j}))})),O.isToggleVisible&&n.jsx(i.Box,e.__assign({sx:{display:"flex",alignItems:"center"}},{children:n.jsx(i.FormControlLabel,{control:n.jsx(i.Switch,{checked:!z,onChange:function(e){var n=e.target.checked;V(!0),setTimeout(function(){P(!n),Rn(),ue(new Set),fe([]),_e.current=[],setTimeout(function(){V(!1)},400)},50)},color:"primary",size:"small",sx:{width:100,height:26,padding:0,"& .MuiSwitch-switchBase":{padding:0,margin:"3px",transitionDuration:"300ms","&.Mui-checked":{transform:"translateX(75px)",color:"#fff","& + .MuiSwitch-track":{backgroundColor:"#5928ED",opacity:1,border:0,"&::before":{content:'"Side by Side"',position:"absolute",left:"13px",top:"50%",transform:"translateY(-50%)",fontSize:"9px",fontWeight:700,color:"#fff",letterSpacing:"0.3px"}}}},"& .MuiSwitch-thumb":{boxSizing:"border-box",width:20,height:20},"& .MuiSwitch-track":{borderRadius:13,backgroundColor:"#9e9e9e",opacity:1,position:"relative","&::after":{content:'"Side by Side"',position:"absolute",right:"13px",top:"50%",transform:"translateY(-50%)",fontSize:"9px",fontWeight:700,color:"#fff",letterSpacing:"0.3px",opacity:1,transition:"opacity 0.2s"}},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{"&::after":{opacity:0}}}}),label:"",labelPlacement:"start",sx:{m:0,gap:1}})}))]})),n.jsx(i.Box,e.__assign({ref:Ne,onScroll:at,sx:{flex:1,minHeight:0,pt:1.5,pb:1,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",overflowY:z?"hidden":"auto",borderTop:mn&&yn?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(i.Box,e.__assign({sx:e.__assign({display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"},z?{flex:1,minHeight:0}:{})},{children:n.jsxs(i.Box,e.__assign({ref:jn,sx:e.__assign({display:"grid",gridTemplateColumns:"minmax(0, 1fr) 180px minmax(0, 1fr)",gap:"10px",maxWidth:"1200px",width:"100%",position:"relative",minHeight:0},z?{flex:1,overflow:"visible"}:{})},{children:[n.jsxs("svg",e.__assign({ref:pe,style:{position:"absolute",top:0,left:0,width:Be.width||"100%",height:Be.height||"100%",pointerEvents:"none",zIndex:10,overflow:"visible",transition:"opacity 0.15s ease-in-out"}},{children:[zn&&!Z&&n.jsxs("g",{children:[n.jsx("line",{x1:zn.x1,y1:zn.y,x2:Math.max(zn.x1,(zn.x1+zn.x2)/2-70),y2:zn.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),n.jsx("line",{x1:Math.min(zn.x2,(zn.x1+zn.x2)/2+70),y1:zn.y,x2:zn.x2,y2:zn.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),Dn.map(function(t){var l,s=t.x1+.5*(t.x2-t.x1),a=(t.y1+t.y2)/2;if("Not Defined"===t.style.label&&!t.hasCognitive)return null;var c=!1;if(t.isSubSection)c=Z&&Hn===t.subSectionKeyPath&&te;else{var u=hn[t.sectionIdx];(z?!(null===(l=null==u?void 0:u.refIndexes)||void 0===l?void 0:l.length)||(null==u?void 0:u.selfIndex)<0:!gn[t.sectionIdx])||(c=Z&&Hn===t.sectionIdx&&te)}if(c)return n.jsxs("g",e.__assign({style:{transition:"opacity 0.2s"}},{children:[n.jsx("defs",{children:n.jsx("marker",e.__assign({id:"arr-".concat(t.id),markerWidth:"7",markerHeight:"5",refX:"7",refY:"2.5",orient:"auto"},{children:n.jsx("polygon",{points:"0 0, 7 2.5, 0 5",fill:t.style.badgeBorder||"#6366F1"})}))}),n.jsx("line",{ref:Tn,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.badgeBorder||"#6366F1",strokeWidth:"1.5",markerEnd:"url(#arr-".concat(t.id,")")})]}),t.id);if(!z){var d=t.isSubSection?y(t.x1,t.y1,t.x2,t.y2):"M ".concat(t.x1," ").concat(t.y1," L ").concat(t.x2," ").concat(t.y2);return n.jsxs("g",{children:[n.jsx("path",{d:d,fill:"none",stroke:t.style.badgeBorder||"#E2E8F0",strokeWidth:"1.5"}),n.jsx("foreignObject",e.__assign({x:s-100,y:a-14,width:"200",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:n.jsx(i.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:n.jsxs(i.Box,e.__assign({onClick:function(e){if(e.stopPropagation(),Ae.open&&le===t.id)Ue();else{var n=hn[t.sectionIdx]||{title:"",content:""},i=gn[t.sectionIdx]||{title:"",content:""};if(t.isSubSection&&t.subSectionKeyPath){for(var r=t.subSectionKeyPath.split("-").map(Number),o=hn[r[0]],l=gn[r[0]],s=1;s<r.length;s++)(null==o?void 0:o.subsections)&&(o=o.subsections[r[s]]),(null==l?void 0:l.subsections)&&(l=l.subsections[r[s]]);o&&(n=o),l&&(i=l)}se(t.id),In(Cn(e.currentTarget,n,i,t.sectionIdx,t.style))}},sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:t.style.badgeBg,color:t.style.badgeText,border:"1px solid ".concat(t.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:600,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"}},{children:[0===t.style.label?"Same":t.style.label,n.jsx(i.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(o.ButtonCognitiveIcon,{})})),n.jsx(r.ChevronDown,{size:11,style:{transform:Ae.open&&le===t.id?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.25s ease"}})]}))}))}))]},t.id)}return null}),ve.map(function(t){var i,r=t.pathD,o=(null===(i=t.style)||void 0===i?void 0:i.badgeBorder)||"#6366F1",l="conn-marker-".concat(t.id),s="".concat(t.id,"-bg"),a="".concat(t.id,"-stroke");return n.jsxs("g",{children:[n.jsx("defs",{children:n.jsx("clipPath",e.__assign({id:"connections-clip"},{children:n.jsx("marker",e.__assign({id:l,markerWidth:"8",markerHeight:"6",refX:"7",refY:"3",orient:"auto"},{children:n.jsx("polygon",{points:"0 0, 8 3, 0 6",fill:o})}))}))}),n.jsx("path",{ref:function(e){xe.current[s]=e},d:r,fill:"none",stroke:"#FFFFFF",strokeWidth:"4",strokeOpacity:"0.7"}),n.jsx("path",{ref:function(e){xe.current[a]=e},d:r,fill:"none",stroke:o,strokeWidth:"1.75",markerEnd:"url(#".concat(l,")")})]},t.id)})]})),n.jsxs(i.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)"},z?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(i.Box,e.__assign({ref:An,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E7E7E9",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"40px",alignItems:"center",overflowX:"hidden"}},{children:n.jsx(i.Tooltip,e.__assign({title:fn,placement:"top"},{children:n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center",textOverflow:"ellipsis",whiteSpace:"normal",width:"100%",height:"40px"}},{children:fn}))}))})),n.jsxs(i.Box,e.__assign({ref:Ye,onScroll:at,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},z?{maxHeight:"calc(100vh - 150px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,mr:"-160px",pr:"172px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:Pe,style:{width:"100%",height:"0px",flexShrink:0}}),xn&&hn.map(function(t,o){var l,s,a=!t.title&&!t.content;if(z&&a)return null;var c=t,u=nt(o),d=z?!(null===(l=c.refIndexes)||void 0===l?void 0:l.length)||c.selfIndex<0:!gn[o],v=z?"number"==typeof c.selfIndex&&c.selfIndex>=0?c.selfIndex+1:null:o+1,f=ce.has(o),p=function(e,n){var t,i,r,o,l,s;if(!e)return n;var a=null!==(s=null!==(o=null!==(i=null===(t=e.evaluation_output)||void 0===t?void 0:t.output_score)&&void 0!==i?i:null===(r=e.evaluation_outputs)||void 0===r?void 0:r.output_score)&&void 0!==o?o:null===(l=e.evaluation_outputs)||void 0===l?void 0:l.output_value)&&void 0!==s?s:e.output_score;return null!=a?a:n}(c.evaluationResult,null==u?void 0:u.deviationLabel);return n.jsx(i.Box,e.__assign({ref:Sn(o),sx:{mb:1,width:"100%"}},{children:n.jsxs(i.Box,e.__assign({sx:{position:"relative",width:"100%"}},{children:[n.jsx(i.Box,e.__assign({ref:Kn.current[o],sx:e.__assign({width:"100%",display:"flex"},f&&{borderRadius:"6px",outline:"2px solid ".concat((null==u?void 0:u.badgeBorder)||"#6366F1"),outlineOffset:"1px"})},{children:dt({section:t,idx:o,columnKey:"left",colRef:h.default.createRef(),mb:0,parentNodeId:(null===(s=null==E?void 0:E.input_index_map)||void 0===s?void 0:s[0])||""})})),z&&u&&n.jsxs(i.Box,e.__assign({ref:Gn.current[o],onClick:function(e){var n=z?gn.find(function(e){var n;return null===(n=c.refIndexes)||void 0===n?void 0:n.includes(e.selfIndex)})||{title:"",content:""}:gn[o]||{title:"",content:""};wn(e,t,d,n,o,u)},sx:{position:"absolute",top:"18px",right:0,transform:"translateY(-50%) translateX(calc(100% + 8px))",display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:u.badgeBg,color:u.badgeText,border:"1px solid ".concat(u.badgeBorder),borderRadius:"12px",px:1.2,py:.4,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",zIndex:20,boxShadow:"0 1px 3px rgba(0,0,0,0.07)"}},{children:[null!==v&&n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"11px",fontWeight:700,pr:.5,borderRight:"1px solid ".concat(u.badgeBorder)}},{children:v})),n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"11px",px:.25}},{children:d?"No Deviation Found":"N/A"===p||"NA"===p?"N/A":0==p||null==p?"Same":"".concat(p)})),n.jsx(r.EllipsisVertical,{size:11,color:u.badgeText})]}))]}))}),"left-row-".concat(o))}),n.jsx("div",{ref:qe,style:{width:"100%",height:"0px",flexShrink:0}})]}))]})),n.jsx(i.Box,e.__assign({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"15px",gap:0}},{children:n.jsx(i.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(i.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:"5px",borderRadius:"20px",bgcolor:"#ECFDF3",border:"1px solid #A7F3D0",color:"#15803D",fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",position:"relative",zIndex:1}},{children:[n.jsx(i.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(o.ButtonCognitiveIcon,{})})),0,"% Similarity",n.jsx(r.ChevronDown,{size:11})]}))}))})),n.jsxs(i.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},z?{flex:1,overflow:"visible",minHeight:0}:{})},{children:[U&&n.jsx(l.default,{sections:11}),n.jsx(i.Box,e.__assign({ref:Mn,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"40px",display:"flex",alignItems:"center",overflowX:"hidden"}},{children:n.jsx(i.Tooltip,e.__assign({title:pn,placement:"top"},{children:n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center",textOverflow:"ellipsis",whiteSpace:"normal",width:"100%",height:"40px"}},{children:pn}))}))})),n.jsxs(i.Box,e.__assign({ref:Le,onScroll:at,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},z?{maxHeight:"calc(100vh - 150px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,ml:"-25px",pl:"45px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:We,style:{width:"100%",height:"0px",flexShrink:0}}),xn&&gn.map(function(t,r){var o,l=t,s=[],a=!1,c=null;if(z){s=hn.filter(function(e){var n;return(null===(n=e.refIndexes)||void 0===n?void 0:n.includes(l.selfIndex))&&e.selfIndex>=0}).map(function(e){return e.selfIndex+1});var u=hn.findIndex(function(e,n){var t;return ce.has(n)&&(null===(t=e.refIndexes)||void 0===t?void 0:t.includes(l.selfIndex))});(a=-1!==u)&&(c=nt(u))}else s=[r+1],(a=ce.has(r))&&(c=nt(r));return n.jsx(i.Box,e.__assign({ref:Jn.current[r],sx:{mb:1,width:"100%"}},{children:n.jsxs(i.Box,e.__assign({sx:{position:"relative",width:"100%"}},{children:[n.jsx(i.Box,e.__assign({ref:Un.current[r],sx:e.__assign({width:"100%",display:"flex"},a&&c&&{borderRadius:"6px",outline:"2px solid ".concat(c.badgeBorder),outlineOffset:"1px"})},{children:dt({section:t,idx:r,columnKey:"right",colRef:h.default.createRef(),mb:0,parentNodeId:(null===(o=null==E?void 0:E.input_index_map)||void 0===o?void 0:o[1])||""})})),z&&!U&&n.jsx(i.Box,e.__assign({ref:Xn.current[r],sx:{position:"absolute",top:"18px",left:0,transform:"translateY(-50%) translateX(calc(-100% - 8px))",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:"11px",bgcolor:"#EEF2FF",color:"#3730A3",border:"1px solid #C7D2FE",borderRadius:"10px",px:1,py:.3,fontWeight:700,whiteSpace:"nowrap",zIndex:20}},{children:s.length>0?s.join(", "):"-"}))]}))}),"right-row-".concat(r))}),n.jsx("div",{ref:ze,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"),t=require("react"),i=require("@mui/material"),r=require("lucide-react"),o=require("../../assests/svg/ButtonCognitiveIcon.js"),l=require("./OverlayComponent.js"),s=require("react-markdown"),a=require("./CognitiveComparehelpers.js"),c=require("./CognitiveCompareConfig.js"),u=require("./CognitivePopup.js"),d=require("./MoreFunctionsPopup.js"),v=require("./LoaderComponent.js"),f=require("rehype-raw");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=p(t),g=p(s),x=p(f),_="::",m=h.default.memo(function(o){var l=o.content,s=o.sxStyles,c=o.deviationBadges,u=void 0===c?[]:c,d=o.highlights,v=void 0===d?[]:d,f=o.maintainRelativeOrder,p=void 0===f||f,h=t.useMemo(function(){return u.reduce(function(n,t){var i;return e.__assign(e.__assign({},n),((i={})[t.id]=t,i))},{})},[u]),_=t.useMemo(function(){return{mark:function(t){var i=t.children;return n.jsx("span",e.__assign({style:{backgroundColor:"#fccccc",borderRadius:"2px"}},{children:i}))},span:function(t){var o,l,s,a,c,u=t.children,d=e.__rest(t,["children"]),v=d["data-badge-id"];if(!v)return n.jsx("span",e.__assign({},d,{children:u}));var f=h[v];return f?n.jsxs(i.Box,e.__assign({component:"span",sx:{position:"static",display:"inline"}},{children:[u,n.jsx(i.Box,e.__assign({ref:f.badgeRef,onClick:f.onClick,sx:e.__assign(e.__assign({position:"absolute",zIndex:30,display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"10px",bgcolor:(null===(o=f.style)||void 0===o?void 0:o.badgeBg)||"#EEF2FF",color:(null===(l=f.style)||void 0===l?void 0:l.badgeText)||"#3730A3",border:"1px solid ".concat((null===(s=f.style)||void 0===s?void 0:s.badgeBorder)||"#C7D2FE"),borderRadius:"12px",px:1,py:.3,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",boxShadow:"0 1px 3px rgba(0,0,0,0.07)"},"left"===f.side?{right:"-16px",transform:"translateY(-20%) translateX(calc(100% + 8px))"}:{left:"-16px",transform:"translateY(-20%) translateX(calc(-100% - 8px))"}),f.isConnected&&f.style&&{outline:"2px solid ".concat(f.style.badgeBorder),outlineOffset:"1px"})},{children:n.jsxs(n.Fragment,{children:[n.jsx(i.Box,e.__assign({component:"span",sx:e.__assign({fontSize:"10px",fontWeight:700},"left"===f.side?{pr:.5,borderRight:"1px solid ".concat((null===(a=f.style)||void 0===a?void 0:a.badgeBorder)||"#C7D2FE")}:{})},{children:f.label})),"left"===f.side&&n.jsxs(n.Fragment,{children:[n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"10px",px:.25}},{children:null!=f.score&&"N/A"!==f.score&&"NA"!==f.score&&0!==f.score?"".concat(f.score):f.isOrphan?"No Deviation Found":"N/A"===f.score||"NA"===f.score?"N/A":"Same"})),n.jsx(r.EllipsisVertical,{size:10,color:(null===(c=f.style)||void 0===c?void 0:c.badgeText)||"#3730A3"})]})]})}))]})):n.jsx("span",e.__assign({},d,{children:u}))}}},[h,p]),m=t.useMemo(function(){var e=l||"",n=function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")};return u.forEach(function(t){if(t.highlight){var i=t.highlight.replace(/\\(['’])/g,"$1");e=e.replace(new RegExp(n(i),"g"),'<span data-badge-id="'.concat(t.id,'"><mark>').concat(i,"</mark></span>"))}}),v.forEach(function(t){t&&(e=e.replace(new RegExp(n(t),"g"),"<mark>".concat(t,"</mark>")))}),e},[l,u,v]);return n.jsx(i.Typography,e.__assign({component:"div",sx:e.__assign(e.__assign({},s),{position:"relative",overflow:"visible","& p, & li, & ul, & ol":{position:"static",overflow:"visible"}})},{children:n.jsx(g.default,e.__assign({components:_,rehypePlugins:[x.default]},{children:a.safeStringify(m).replace(/\\n/g,"\n")}))}))},function(e,n){if(e.content!==n.content)return!1;if(e.sxStyles!==n.sxStyles)return!1;if(e.maintainRelativeOrder!==n.maintainRelativeOrder)return!1;var t=e.highlights||[],i=n.highlights||[];if(t.length!==i.length)return!1;for(var r=0;r<t.length;r++)if(t[r]!==i[r])return!1;return!0}),y=function(e,n,t,i,r){void 0===r&&(r=14);var o=e+.5*(t-e),l=i-n;if(Math.abs(l)<3)return"M ".concat(e," ").concat(n," H ").concat(t);var s=l>0?1:-1,a=Math.min(r,Math.abs(l)/2,Math.abs(o-e)/2,Math.abs(t-o)/2);return["M ".concat(e," ").concat(n),"H ".concat(o-a),"Q ".concat(o," ").concat(n," ").concat(o," ").concat(n+s*a),"V ".concat(i-s*a),"Q ".concat(o," ").concat(i," ").concat(o+a," ").concat(i),"H ".concat(t)].join(" ")},b={id:"",title:""},S={open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,isOrphan:!1,docData:null,deviationData:null},R=function(e,n,t,i,r){void 0===t&&(t=300);var o=e.style.scrollBehavior;e.style.scrollBehavior="auto";var l=e.scrollTop,s=n-l,a=null,c=function(u){null===a&&(a=u);var d,v=u-a;v<t?(e.scrollTop=(d=v,d/=t,s*(--d*d*d+1)+l),r&&r(),requestAnimationFrame(c)):(e.scrollTop=n,e.style.scrollBehavior=o,r&&r(),i&&i())};requestAnimationFrame(c)};exports.SHARED_MARKDOWN_STYLES=c.SHARED_MARKDOWN_STYLES,exports.default=function(s){var f,p,g,x,C,I,w,F,B=s.componentHeaderText,j=void 0===B?"Contract Comparison":B,E=s.treeData,T=s.comparisonConfig,A=s.leftColumnTitleText,M=s.rightColumnTitleText,k=s.markdownStyles,D=s.displayConfig,O=void 0===D?{isHeaderVisible:!0,isToggleVisible:!0,maintainRelativeOrder:!1}:D,N=s.popupConfig,H=s.deviationData,L=void 0===H?{}:H,W=t.useState(O.maintainRelativeOrder),z=W[0],P=W[1],q=t.useState(!1),Y=q[0],V=q[1],K=t.useState(!1),U=K[0],G=K[1],X=t.useState(null),J=X[0],$=X[1],Q=t.useState(!1),Z=Q[0],ee=Q[1],ne=t.useState(!1),te=ne[0],ie=ne[1],re=t.useRef(!1),oe=t.useState(null),le=oe[0],se=oe[1],ae=t.useState(new Set),ce=ae[0],ue=ae[1],de=t.useState([]),ve=de[0],fe=de[1],pe=t.useRef(null),he=t.useRef(!1),ge=t.useRef(null),xe=t.useRef({}),_e=t.useRef([]),me=t.useRef(!1),ye=t.useRef(!1),be=t.useRef(null),Se=t.useMemo(function(){return(null==E?void 0:E.cognitive_decisioning)||{}},[E]),Re=t.useState(null),Ce=Re[0],Ie=Re[1],we=t.useRef(null),Fe=t.useState({width:0,height:0}),Be=Fe[0],je=Fe[1],Ee=t.useMemo(function(){return e.__assign(e.__assign({},c.SHARED_MARKDOWN_STYLES),k)},[k]),Te=t.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,isOrphan:!1,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,docData:null,deviationData:null}),Ae=Te[0],Me=Te[1],ke=t.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,isOrphan:!1,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null,docData:null,deviationData:null}),De=ke[0],Oe=ke[1],Ne=t.useRef(null),He=t.useRef(null),Le=t.useRef(null),We=t.useRef(null),ze=t.useRef(null),Pe=t.useRef(null),qe=t.useRef(null),Ye=t.useRef(null),Ve=t.useRef(!1),Ke=t.useRef(null);t.useEffect(function(){Ke.current=null},[Ae.sectionIdx,Ae.open]);var Ue=t.useCallback(function(){Ie(null),Me(S),se(null)},[]),Ge=t.useCallback(function(){Oe(S)},[]),Xe=t.useCallback(function(){var e;if(Ae.anchorEl&&Ae.refSectionTitle){var n=Ae.anchorEl.getBoundingClientRect(),t=(null===(e=null==we?void 0:we.current)||void 0===e?void 0:e.offsetHeight)||0,i=Math.min(680,window.innerWidth-24),r=window.innerHeight-n.bottom-12-12,o=n.top-12-12,l=r<t&&o>r;null!==Ke.current?!0===Ke.current&&(l=o>=t||o>=r):l=!(r>=t||r>=o),Ke.current=l;var s=l?o:r,a=Math.min(t||9999,s),c=l?n.top-12-a:n.bottom+12,u=n.left+n.width/2,d=u-i/2,v=Math.max(12,Math.min(d,window.innerWidth-i-12)),f=Math.max(14,Math.min(u-v,i-10-4));Ie({top:c,left:v,arrowLeft:f,openAbove:l,maxHeight:s})}},[Ae.anchorEl,Ae.refSectionTitle]);t.useEffect(function(){if(Ae.open){window.addEventListener("resize",Xe);var e=requestAnimationFrame(Xe),n=null;return we.current&&(n=new ResizeObserver(function(){cancelAnimationFrame(e),e=requestAnimationFrame(Xe)})).observe(we.current),function(){cancelAnimationFrame(e),window.removeEventListener("resize",Xe),n&&n.disconnect()}}},[Ae.open,Xe]),t.useEffect(function(){var e=Ne.current;if(e&&Ae.open){var n=function(e){we.current&&we.current.contains(e.target)||(Ie(null),Ue())};return e.addEventListener("scroll",n,{capture:!0}),window.addEventListener("scroll",n,{capture:!0}),function(){e.removeEventListener("scroll",n,{capture:!0}),window.removeEventListener("scroll",n,{capture:!0})}}},[Ae.open,Ue]),t.useEffect(function(){var e=Ne.current;if(e&&De.open){var n=function(){Ge()};return e.addEventListener("scroll",n,{capture:!0}),window.addEventListener("scroll",n,{capture:!0}),function(){e.removeEventListener("scroll",n,{capture:!0}),window.removeEventListener("scroll",n,{capture:!0})}}},[De.open,Ge]);var Je=t.useMemo(function(){var n,t,i,r,o,l,s,a,u,d,v,f;return{fields:null!==(n=null==T?void 0:T.fields)&&void 0!==n?n:c.DEFAULT_FIELD_CONFIG,thresholds:{high:null!==(i=null===(t=null==T?void 0:T.thresholds)||void 0===t?void 0:t.high)&&void 0!==i?i:c.DEFAULT_COMPARISON_CONFIG.thresholds.high,medium:null!==(o=null===(r=null==T?void 0:T.thresholds)||void 0===r?void 0:r.medium)&&void 0!==o?o:c.DEFAULT_COMPARISON_CONFIG.thresholds.medium,exact:null!==(s=null===(l=null==T?void 0:T.thresholds)||void 0===l?void 0:l.exact)&&void 0!==s?s:c.DEFAULT_COMPARISON_CONFIG.thresholds.exact},relationStyles:{noContent:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.noContent),(null===(a=null==T?void 0:T.relationStyles)||void 0===a?void 0:a.noContent)||{}),high:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.high),(null===(u=null==T?void 0:T.relationStyles)||void 0===u?void 0:u.high)||{}),exact:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.exact),(null===(d=null==T?void 0:T.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.medium),(null===(v=null==T?void 0:T.relationStyles)||void 0===v?void 0:v.medium)||{}),low:e.__assign(e.__assign({},c.DEFAULT_COMPARISON_CONFIG.relationStyles.low),(null===(f=null==T?void 0:T.relationStyles)||void 0===f?void 0:f.low)||{})}}},[T]),$e=t.useMemo(function(){if(E&&Object.keys(E).length>0)try{var n=function(n,t,i){var r,o,l,s;void 0===t&&(t=!1),void 0===i&&(i=null);var c=n.nodes||n,u=[],d=[],v=n.base_root_id,f=n.input_index_map||{0:"left",1:"right"},p=n[v]||c[v];if(!p||!1===p.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var h=function(t,r){var o,l,s,u=n[t]||c[t];if(!u||!1===u.display_node)return null;var d=a.getSideData(u,r,f),v=!1!==(null===(o=d.attributes)||void 0===o?void 0:o.display_title),p=!1!==(null===(l=d.attributes)||void 0===l?void 0:l.display_content),g=!!d.title.trim(),x=!!d.content.trim(),_=a.getRationale(u),m=(null===(s=null==i?void 0:i[t])||void 0===s?void 0:s.evaluation_result)||u.evaluation_result||null,y=[];u.next&&Object.values(u.next).forEach(function(e){var n=c[e];if(n&&!1!==n.display_node){var t=h(e,r);t&&y.push(t)}});var b=!(!g&&!x);return e.__assign(e.__assign({id:t,title:g?d.title:"",content:x?d.content:"",displayTitle:v,displayContent:p,subsections:y},b?_:{score:void 0,relation:"not_defined"}),{evaluationResult:m})};if(t){var g=function(t,r){var o,l,s,u,d,v,p,h,x,_,m,y,b,S,R,C,I,w,F,B,j;void 0===r&&(r=0);var E=[],T=[];if(!t)return{refSections:E,baseSections:T};var A={},M={},k=-1,D=-1;for(var O in t){var N=t[O],H=n[N]||c[N];if(H&&!1!==H.display_node){var L=a.getRationale(H),W=(null===(o=null==i?void 0:i[N])||void 0===o?void 0:o.evaluation_result)||H.evaluation_result||null,z=a.getSideData(H,"1",f),P=a.getSideData(H,"0",f),q=!1!==(null===(l=z.attributes)||void 0===l?void 0:l.display_title)&&z.title.trim()||!1!==(null===(s=z.attributes)||void 0===s?void 0:s.display_content)&&z.content.trim(),Y=!1!==(null===(u=P.attributes)||void 0===u?void 0:u.display_title)&&P.title.trim()||!1!==(null===(d=P.attributes)||void 0===d?void 0:d.display_content)&&P.content.trim(),V=Number(null!==(p=null===(v=z.attributes)||void 0===v?void 0:v.display_index)&&void 0!==p?p:k--),K=Number(null!==(x=null===(h=P.attributes)||void 0===h?void 0:h.display_index)&&void 0!==x?x:D--),U=A[V]||e.__assign(e.__assign({id:N,title:!1!==(null===(_=z.attributes)||void 0===_?void 0:_.display_title)?z.title:"",content:!1!==(null===(m=z.attributes)||void 0===m?void 0:m.display_content)?z.content:"",subsections:[]},q?L:{score:void 0,relation:"not_defined"}),{refIndexes:[],selfIndex:V,evaluationResult:W,displayContent:null===(y=z.attributes)||void 0===y?void 0:y.display_content,displayTitle:null===(b=z.attributes)||void 0===b?void 0:b.display_title}),G=M[K]||e.__assign(e.__assign({id:N,title:!1!==(null===(S=P.attributes)||void 0===S?void 0:S.display_title)?P.title:"",content:!1!==(null===(R=P.attributes)||void 0===R?void 0:R.display_content)?P.content:"",subsections:[]},Y?L:{score:void 0,relation:"not_defined"}),{refIndexes:[],selfIndex:K,evaluationResult:W,displayContent:null===(C=P.attributes)||void 0===C?void 0:C.display_content,displayTitle:null===(I=P.attributes)||void 0===I?void 0:I.display_title});Number(V)>=0&&Number(K)>=0&&((null===(w=U.refIndexes)||void 0===w?void 0:w.includes(Number(K)))||null===(F=U.refIndexes)||void 0===F||F.push(Number(K)),(null===(B=G.refIndexes)||void 0===B?void 0:B.includes(Number(V)))||null===(j=G.refIndexes)||void 0===j||j.push(Number(V))),A[V]=U,M[K]=G;var X=g(H.next,r+1),J=X.refSections,$=X.baseSections;J.length>0&&(U.subsections=e.__spreadArray(e.__spreadArray([],U.subsections||[],!0),J,!0)),$.length>0&&(G.subsections=e.__spreadArray(e.__spreadArray([],G.subsections||[],!0),$,!0))}}return E=Object.values(A).map(function(e){return e}),T=Object.values(M).map(function(e){return e}),E.sort(function(e,n){return e.selfIndex<0&&n.selfIndex>=0?1:e.selfIndex>=0&&n.selfIndex<0?-1:e.selfIndex-n.selfIndex}),T.sort(function(e,n){return e.selfIndex<0&&n.selfIndex>=0?1:e.selfIndex>=0&&n.selfIndex<0?-1:e.selfIndex-n.selfIndex}),{refSections:E,baseSections:T}},x=g(p.next),_=x.refSections,m=x.baseSections;d=_,u=m}else p.next&&Object.values(p.next).forEach(function(e){var t=n[e]||c[e];t&&!1!==t.display_node&&(u.push(h(e,"0")||{id:e,title:"",content:"",subsections:[]}),d.push(h(e,"1")||{id:e,title:"",content:"",subsections:[]}))});return{activeProposed:{title:(null===(o=null===(r=p.comparison_inputs)||void 0===r?void 0:r[f[0]])||void 0===o?void 0:o.title)||"Uploaded Contract",description:p.decision_scope_description||"",sections:u},activeVariants:[{id:"tree-variant-1",title:(null===(s=null===(l=p.comparison_inputs)||void 0===l?void 0:l[f[1]])||void 0===s?void 0:s.title)||"Reference Template",similarity:0,sections:d,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:p.decision_scope_description||""},fields:{}}}}]}}(E,z,L);return e.__assign(e.__assign({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:[],parseError:"Tree data is required"}},[JSON.stringify(E),z,JSON.stringify(L)]),Qe=$e.activeProposed,Ze=$e.activeVariants,en=$e.parseError;t.useEffect(function(){en&&$("Failed to load comparison: ".concat(en))},[en]);var nn=t.useState(null),tn=nn[0];nn[1];var rn=t.useState({}),on=rn[0],ln=rn[1],sn=t.useState({}),an=sn[0],cn=sn[1],un=(null==Ze?void 0:Ze[0])||b,dn=null===(g=null===(f=null==E?void 0:E.documents)||void 0===f?void 0:f[null===(p=null==E?void 0:E.input_index_map)||void 0===p?void 0:p[0]])||void 0===g?void 0:g.title,vn=null===(I=null===(x=null==E?void 0:E.documents)||void 0===x?void 0:x[null===(C=null==E?void 0:E.input_index_map)||void 0===C?void 0:C[1]])||void 0===I?void 0:I.title,fn=a.safeStringify(A||dn||"Uploaded Contract"),pn=a.safeStringify(M||vn||"Reference Template"),hn=t.useMemo(function(){return(null==Qe?void 0:Qe.sections)||[]},[null==Qe?void 0:Qe.sections]),gn=t.useMemo(function(){return un.sections||[]},[un.sections]),xn=hn.length>0||gn.length>0,_n=un.analysis,mn=a.safeStringify(null===(F=null===(w=null==_n?void 0:_n.rule_difference_comparison)||void 0===w?void 0:w.summary)||void 0===F?void 0:F.overall_summary),yn=!!mn.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),bn=t.useRef({}),Sn=function(e){return bn.current[e]||(bn.current[e]=h.default.createRef()),bn.current[e]},Rn=t.useCallback(function(){var e,n,t,i;ee(!1),ye.current=!1;var r=be.current,o=En.current;if(null!==r){var l="string"==typeof r?null===(e=$n.current[r.split(_)[0]])||void 0===e?void 0:e.current:null===(n=Kn.current[r])||void 0===n?void 0:n.current;l&&(l.style.paddingTop="0px")}if(null!==o){var s="string"==typeof o?null===(t=Qn.current[o.split(_)[0]])||void 0===t?void 0:t.current:null===(i=Un.current[o])||void 0===i?void 0:i.current;s&&(s.style.paddingTop="0px")}Ln(null),be.current=null,En.current=null,ie(!1),G(!1),We.current&&(We.current.style.height="0px"),ze.current&&(ze.current.style.height="0px"),Pe.current&&(Pe.current.style.height="0px"),qe.current&&(qe.current.style.height="0px")},[]),Cn=t.useCallback(function(e,n,t,i,r,o){var l,s,c=a.safeStringify(n.id)||a.safeStringify(t.id)||"",u=(c?Se[c]:null)||n.cognitiveData||t.cognitiveData||{section_id:c,decisioning:[],gap:[],relevance_score:0},d=null!==(s=null===(l=bn.current[i])||void 0===l?void 0:l.current)&&void 0!==s?s:null;return{open:!0,sectionTitle:n.displayTitle?n.title:"no title",refSectionTitle:n.displayTitle?n.title:"no title",cognitiveData:u,anchorEl:e,sectionAnchorEl:d,badgeStyle:o||null,sectionIdx:i,docData:{documents:null==E?void 0:E.documents,input_index_map:null==E?void 0:E.input_index_map},deviationData:n.evaluationResult||t.evaluationResult||null,isOrphan:!!r}},[Se,E]),In=t.useCallback(function(e){Ge(),Ie(null),Me(e)},[Ge]),wn=function(e,n,t,i,r,o){e.stopPropagation(),De.open&&De.sectionIdx===r?Ge():(Ue(),Oe(Cn(e.currentTarget,n,i,r,t,o)))},Fn=t.useCallback(function(){null!==De.sectionIdx&&De.anchorEl?In(e.__assign(e.__assign({},De),{open:!0})):Ge()},[De,Ge,In]),Bn=t.useCallback(function(){var e=De.sectionIdx,n=De.isOrphan;Ge(),null!==e&&(n?$("No counterpart exists to connect to."):(ye.current&&Rn(),ue(function(n){return n.has(e)?new Set:new Set([e])})))},[De.sectionIdx,Ge,Rn]),jn=t.useRef(null),En=t.useRef(null),Tn=t.useRef(null),An=t.useRef(null),Mn=t.useRef(null),kn=t.useState([]),Dn=kn[0],On=kn[1],Nn=t.useState(null),Hn=Nn[0],Ln=Nn[1];t.useRef(null);var Wn=t.useState(null),zn=Wn[0],Pn=Wn[1],qn=t.useMemo(function(){return Je.fields.filter(function(e){var n=e.key;return(!xn||"description"!==n)&&(a.hasValue(null==Qe?void 0:Qe[n])||a.hasValue(un[n]))})},[Qe,un,xn,Je.fields]),Yn=t.useRef({}),Vn=t.useRef({}),Kn=t.useRef({}),Un=t.useRef({}),Gn=t.useRef({}),Xn=t.useRef({}),Jn=t.useRef({}),$n=t.useRef({}),Qn=t.useRef({});qn.forEach(function(e){for(var n=e.key,t=0;t<Math.max(hn.length,gn.length);t+=1)Kn.current[t]||(Kn.current[t]=h.default.createRef()),Un.current[t]||(Un.current[t]=h.default.createRef()),Gn.current[t]||(Gn.current[t]=h.default.createRef()),Xn.current[t]||(Xn.current[t]=h.default.createRef()),Jn.current[t]||(Jn.current[t]=h.default.createRef());Yn.current[n]||(Yn.current[n]=h.default.createRef()),Vn.current[n]||(Vn.current[n]=h.default.createRef())});for(var Zn=0;Zn<Math.max(hn.length,gn.length);Zn+=1)Kn.current[Zn]||(Kn.current[Zn]=h.default.createRef()),Un.current[Zn]||(Un.current[Zn]=h.default.createRef()),Gn.current[Zn]||(Gn.current[Zn]=h.default.createRef()),Xn.current[Zn]||(Xn.current[Zn]=h.default.createRef()),Jn.current[Zn]||(Jn.current[Zn]=h.default.createRef());t.useEffect(function(){if(tn){var e=Je.fields.find(function(e){return e.analysisKey===tn||e.key===tn});if(e){var n=Yn.current[e.key]||Vn.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[tn,Je.fields]);var et=t.useCallback(function(e){var n,t,i,r,o,l,s,a,c,u=null===(n=null==_n?void 0:_n.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!u||!u[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var d=u[e],v=(null==d?void 0:d.relation)||(null===(i=null===(t=null==d?void 0:d.highlights)||void 0===t?void 0:t.ruleA_spans)||void 0===i?void 0:i.length)||(null===(o=null===(r=null==d?void 0:d.highlights)||void 0===r?void 0:r.ruleB_spans)||void 0===o?void 0:o.length)||(null==d?void 0:d.mappings)&&d.mappings.length>0;if(d.mappings){var f=d.mappings[0]||{};return{score:d.score,relation:f.relation||"",highlightsA:(null===(l=f.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(s=f.highlights)||void 0===s?void 0:s.ruleB_spans)||[],hasContent:!!v}}return{score:d.score,relation:d.relation||"",highlightsA:(null===(a=d.highlights)||void 0===a?void 0:a.ruleA_spans)||[],highlightsB:(null===(c=d.highlights)||void 0===c?void 0:c.ruleB_spans)||[],hasContent:!!v}},[_n]),nt=t.useCallback(function(n){var t,i,r,o=hn[n],l=gn[n],s=(null==o?void 0:o.relation)&&"not_defined"!==o.relation,c=(null==l?void 0:l.relation)&&"not_defined"!==l.relation;a.safeStringify(null==o?void 0:o.id)||a.safeStringify(null==l?void 0:l.id);var u=!(!(null==o?void 0:o.cognitiveData)&&!(null==l?void 0:l.cognitiveData));if(!s&&!c&&!u)return e.__assign(e.__assign({},Je.relationStyles.noContent),{label:"Not Defined"});var d=null!==(i=null!==(t=null==o?void 0:o.evaluationResult)&&void 0!==t?t:null==l?void 0:l.evaluationResult)&&void 0!==i?i:null,v=null===(r=null==d?void 0:d.evaluation_outputs)||void 0===r?void 0:r.output_value;return null!=d?e.__assign(e.__assign({},Je.relationStyles.low),{label:null!=v?v:""}):e.__assign(e.__assign({},Je.relationStyles.low),{label:"N/A"})},[hn,gn,Se,Je,et]),tt=t.useCallback(function(n){for(var t,i,r,o,l,s,c=n.split("-").map(Number),u=hn[c[0]],d=gn[c[0]],v=1;v<c.length;v++)(null==u?void 0:u.subsections)&&(u=u.subsections[c[v]]),(null==d?void 0:d.subsections)&&(d=d.subsections[c[v]]);if(!u&&!d)return null;var f=(null==u?void 0:u.relation)&&"not_defined"!==u.relation,p=(null==d?void 0:d.relation)&&"not_defined"!==d.relation,h=a.safeStringify(null==u?void 0:u.id)||a.safeStringify(null==d?void 0:d.id)||"",g=!(!(null==u?void 0:u.cognitiveData)&&!(null==d?void 0:d.cognitiveData));if(!f&&!p&&!g)return e.__assign(e.__assign({},Je.relationStyles.noContent),{label:"Not Defined"});null!==(i=null!==(t=null==u?void 0:u.cognitiveRelevanceScore)&&void 0!==t?t:null==d?void 0:d.cognitiveRelevanceScore)&&void 0!==i||h&&(null===(r=Se[h])||void 0===r||r.relevance_score);var x=null!==(l=null!==(o=null==u?void 0:u.evaluationResult)&&void 0!==o?o:null==d?void 0:d.evaluationResult)&&void 0!==l?l:null,_=null===(s=null==x?void 0:x.evaluation_outputs)||void 0===s?void 0:s.output_value;return null!=x?e.__assign(e.__assign({},Je.relationStyles.low),{label:null!=_?_:""}):e.__assign(e.__assign({},Je.relationStyles.low),{label:"N/A"})},[hn,gn,Se,Je]),it=t.useCallback(function(){var e,n,t,i,r,o,l,s,a,c,u,d,v,f,p,h,g,x,m,b,S,R;if(!Ve.current&&!he.current){Ve.current=!0;try{if(!jn.current)return;var C=function(e){var n=e.split("-"),t=n[0];if(!on[t]&&!1===z)return!1;if(z&&!on["left-".concat(t)]&&!on["right-".concat(t)]&&!on[t])return!1;for(var i=t,r=1;r<n.length-1;r++)if(i+="-".concat(n[r]),!an[i])return!1;return!0},I=jn.current.getBoundingClientRect();je({width:I.width,height:I.height});var w=[];if(qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;r&&o&&(r.style.height="auto",o.style.height="auto",r.style.minHeight="0px",o.style.minHeight="0px")}),!he.current){for(var F=0;F<Math.max(hn.length,gn.length);F++){var B=null===(e=Kn.current[F])||void 0===e?void 0:e.current,j=null===(n=Un.current[F])||void 0===n?void 0:n.current;B&&(B.style.height="auto",B.style.minHeight="0px"),j&&(j.style.height="auto",j.style.minHeight="0px")}z||Object.keys($n.current).forEach(function(e){var n,t;if(C(e)){var i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;i&&r&&(i.style.height="auto",r.style.height="auto",i.style.minHeight="0px",r.style.minHeight="0px")}})}var E={};qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;if(r&&o){var l=r.getBoundingClientRect(),s=o.getBoundingClientRect();E[i]=Math.max(l.height,s.height)}});var T={left:{},right:{}},A={};if(!he.current)if(z){if(Z&&null!==Hn)if("number"==typeof Hn){var M=Hn,k=hn[M],D=null===(r=Kn.current[M])||void 0===r?void 0:r.current;D&&k&&(k.refIndexes||[]).forEach(function(e){var n,t=gn.findIndex(function(n){return n.selfIndex===e}),i=null===(n=Un.current[t])||void 0===n?void 0:n.current;if(i&&(on["left-".concat(M)]||on["right-".concat(t)])){var r=Math.max(D.getBoundingClientRect().height,i.getBoundingClientRect().height);T.left[M]=Math.max(T.left[M]||0,r),T.right[t]=Math.max(T.right[t]||0,r)}})}else{var O=Hn.split(_)[0];B=null===(o=$n.current[O])||void 0===o?void 0:o.current,j=null===(l=Qn.current[O])||void 0===l?void 0:l.current;if(B&&j){N=Math.max(B.getBoundingClientRect().height,j.getBoundingClientRect().height);A[O]=Math.max(A[O]||0,N)}}}else{Object.keys($n.current).forEach(function(e){var n,t;if(C(e)){var i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;if(i&&r&&null!==i.offsetParent&&null!==r.offsetParent){var o=i.getBoundingClientRect(),l=r.getBoundingClientRect(),s=Math.max(o.height,l.height);A[e]=s,i.style.minHeight="".concat(s,"px"),r.style.minHeight="".concat(s,"px")}}});for(F=0;F<Math.min(hn.length,gn.length);F++){var B=null===(t=Kn.current[F])||void 0===t?void 0:t.current,j=null===(i=Un.current[F])||void 0===i?void 0:i.current;if(B&&j){var N=Math.max(B.getBoundingClientRect().height,j.getBoundingClientRect().height);T.left[F]=N,T.right[F]=N}}}if(qn.forEach(function(e){var n,t,i=e.key,r=null===(n=Yn.current[i])||void 0===n?void 0:n.current,o=null===(t=Vn.current[i])||void 0===t?void 0:t.current;if(r&&o){var l=E[i];r.style.minHeight="".concat(l,"px"),o.style.minHeight="".concat(l,"px")}}),he.current||(Object.entries(T.left).forEach(function(e){var n,t=e[0],i=e[1],r=null===(n=Kn.current[Number(t)])||void 0===n?void 0:n.current;r&&(r.style.minHeight="".concat(i,"px"))}),Object.entries(T.right).forEach(function(e){var n,t=e[0],i=e[1],r=null===(n=Un.current[Number(t)])||void 0===n?void 0:n.current;r&&(r.style.minHeight="".concat(i,"px"))}),z||Object.keys(A).forEach(function(e){var n,t,i=null===(n=$n.current[e])||void 0===n?void 0:n.current,r=null===(t=Qn.current[e])||void 0===t?void 0:t.current;if(i&&r&&A[e]){var o=A[e];i.style.minHeight="".concat(o,"px"),r.style.minHeight="".concat(o,"px")}})),z)hn.forEach(function(e,n){var t;(null===(t=Kn.current[n])||void 0===t?void 0:t.current)&&(e.refIndexes||[]).forEach(function(e){var t,i,r,o,l,s,a,c,u,d,v=gn.findIndex(function(n){return n.selfIndex===e});if(-1!==v){var f=null===(t=Gn.current[n])||void 0===t?void 0:t.current,p=null===(i=Xn.current[v])||void 0===i?void 0:i.current;if(f&&p){var h=f.getBoundingClientRect(),g=p.getBoundingClientRect(),x=h.right-I.left,_=g.left-I.left,m=h.top+h.height/2-I.top,y=g.top+g.height/2-I.top;if(Z&&Hn===n){var b=null!==(o=null===(r=Ye.current)||void 0===r?void 0:r.getBoundingClientRect().top)&&void 0!==o?o:0,S=null!==(s=null===(l=Le.current)||void 0===l?void 0:l.getBoundingClientRect().top)&&void 0!==s?s:0,R=b+(null!==(c=null===(a=Ye.current)||void 0===a?void 0:a.clientHeight)&&void 0!==c?c:1/0),C=S+(null!==(d=null===(u=Le.current)||void 0===u?void 0:u.clientHeight)&&void 0!==d?d:1/0),F=h.top+h.height/2,B=function(e,n,t){return Math.max(n,Math.min(t,e))};m=B(F,b,R)-I.top,y=B(F,S,C)-I.top}var j=nt(n);j&&w.push({id:"line-".concat(n,"-").concat(v),x1:x,y1:m,x2:_,y2:y,style:j,sectionIdx:n,targetRightIdx:v})}}})});else for(F=0;F<Math.min(hn.length,gn.length);F++){var H=null===(s=Kn.current[F])||void 0===s?void 0:s.current,L=null===(a=Un.current[F])||void 0===a?void 0:a.current;if(H&&L){var W=H.getBoundingClientRect(),P=L.getBoundingClientRect(),q=Math.max(W.top,P.top)+18-I.top,Y=(null===(c=gn[F])||void 0===c?void 0:c.id)||"sec-".concat(F);(G=nt(F))&&w.push({id:Y,x1:W.right-I.left,y1:q,x2:P.left-I.left,y2:q,style:G,sectionIdx:F,hasCognitive:!!((null===(u=hn[F])||void 0===u?void 0:u.cognitiveData)||(null===(d=gn[F])||void 0===d?void 0:d.cognitiveData)||Y&&Se[Y]),isSubSection:!1})}}if(Z&&"string"==typeof Hn){var V=Hn,K=(O=V.split(_)[0],null===(v=Gn.current[V])||void 0===v?void 0:v.current),U=null===(f=Xn.current[V])||void 0===f?void 0:f.current;if(K&&U){var G,X=K.getBoundingClientRect(),J=U.getBoundingClientRect(),$=X.right-I.left,Q=J.left-I.left,ee=X.top+X.height/2-I.top,ne=J.top+J.height/2-I.top;if(z){var te=null!==(h=null===(p=Ye.current)||void 0===p?void 0:p.getBoundingClientRect().top)&&void 0!==h?h:0,ie=null!==(x=null===(g=Le.current)||void 0===g?void 0:g.getBoundingClientRect().top)&&void 0!==x?x:0,re=te+(null!==(b=null===(m=Ye.current)||void 0===m?void 0:m.clientHeight)&&void 0!==b?b:1/0),oe=ie+(null!==(R=null===(S=Le.current)||void 0===S?void 0:S.clientHeight)&&void 0!==R?R:1/0),le=function(e,n,t){return Math.max(n,Math.min(t,e))};ee=le(X.top+X.height/2,te,re)-I.top,ne=le(J.top+J.height/2,ie,oe)-I.top}(G=tt(O))&&w.push({id:"line-subsec-".concat(V),x1:$,y1:ee,x2:Q,y2:ne,style:G,sectionIdx:Number(O.split("-")[0]),isSubSection:!0,subSectionKeyPath:V})}}if(On(w),An.current&&Mn.current){var se=An.current.getBoundingClientRect(),ae=Mn.current.getBoundingClientRect(),ue=(se.top+se.height/2-I.top+ae.top+ae.height/2-I.top)/2;Pn({x1:se.right-I.left,x2:ae.left-I.left,y:ue})}else Pn(null);if(ce.size>0){var de=[],ve=Ye.current,pe=Le.current;if(ve&&pe){var ge=[],xe=ve.getBoundingClientRect().top,me=pe.getBoundingClientRect().top,ye=xe+ve.clientHeight,be=me+pe.clientHeight,Re=ve.scrollTop,Ce=pe.scrollTop,Ie=I.top,we=function(e,n,t){return Math.max(n,Math.min(t,e))};ce.forEach(function(e){var n,t,i,r,o;if("string"==typeof e){var l=e,s=l.split(_)[0],a=null===(n=Gn.current[l])||void 0===n?void 0:n.current,c=null===(t=Xn.current[l])||void 0===t?void 0:t.current;if(!a||!c)return;var u=a.getBoundingClientRect(),d=c.getBoundingClientRect(),v=tt(s),f=(E=u.right-I.left)+.5*((T=d.left-I.left-0)-E),p=u.top+u.height/2,h=d.top+d.height/2,g=p-xe+Re,x=h-me+Ce,m="conn-subsec-".concat(l);ge.push({lhsScrollY:g,rhsScrollY:x,x1:E,x2:T,containerTop:Ie,leftIdx:l,rhsArrayIdx:l,styleColor:(null==v?void 0:v.badgeBorder)||"#6366F1",styleId:m});var b=we(p,xe,ye),S=we(h,me,be),R=b-Ie,C=S-Ie,w=h>=me-4&&h<=be+4,F="";F=(A=p>=xe-4&&p<=ye+4)&&w?y(E,R,T,C):A&&!w?"M ".concat(E,",").concat(R," L ").concat(f,",").concat(R," L ").concat(f,",").concat(C):!A&&w?"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C," L ").concat(T,",").concat(C):"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C),de.push({id:m,pathD:F,style:v,leftIdx:l,rhsArrayIdx:l})}else if(z){var B=hn[e];if(!(null===(o=null==B?void 0:B.refIndexes)||void 0===o?void 0:o.length))return;B.refIndexes.forEach(function(n){var t,i,r=gn.findIndex(function(e){return e.selfIndex===n});if(-1!==r){var o=null===(t=Gn.current[e])||void 0===t?void 0:t.current,l=null===(i=Xn.current[r])||void 0===i?void 0:i.current;if(o&&l){var s=o.getBoundingClientRect(),a=l.getBoundingClientRect(),c=nt(e),u=s.right-I.left,d=a.left-I.left-0,v=u+.5*(d-u),f=s.top+s.height/2,p=a.top+a.height/2,h=f-xe+Re,g=p-me+Ce,x="conn-".concat(e,"-").concat(r);ge.push({lhsScrollY:h,rhsScrollY:g,x1:u,x2:d,containerTop:Ie,leftIdx:e,rhsArrayIdx:r,styleColor:(null==c?void 0:c.badgeBorder)||"#6366F1",styleId:x});var _=we(f,xe,ye),m=we(p,me,be),b=_-Ie,S=m-Ie,R=f>=xe-4&&f<=ye+4,C=p>=me-4&&p<=be+4,w="";w=R&&C?y(u,b,d,S):R&&!C?"M ".concat(u,",").concat(b," L ").concat(v,",").concat(b," L ").concat(v,",").concat(S):!R&&C?"M ".concat(v,",").concat(b," L ").concat(v,",").concat(S," L ").concat(d,",").concat(S):"M ".concat(v,",").concat(b," L ").concat(v,",").concat(S),de.push({id:x,pathD:w,style:c,leftIdx:e,rhsArrayIdx:r})}}})}else{var j=e;a=null===(i=Gn.current[e])||void 0===i?void 0:i.current,c=null===(r=Xn.current[j])||void 0===r?void 0:r.current;if(!a||!c)return;var E,T;u=a.getBoundingClientRect(),d=c.getBoundingClientRect(),v=nt(e),f=(E=u.right-I.left)+.5*((T=d.left-I.left-0)-E),p=u.top+u.height/2,h=d.top+d.height/2,g=p-xe+Re,x=h-me+Ce,m="conn-".concat(e,"-").concat(j);ge.push({lhsScrollY:g,rhsScrollY:x,x1:E,x2:T,containerTop:Ie,leftIdx:e,rhsArrayIdx:j,styleColor:(null==v?void 0:v.badgeBorder)||"#6366F1",styleId:m});var A;b=we(p,xe,ye),S=we(h,me,be),R=b-Ie,C=S-Ie,w=h>=me-4&&h<=be+4,F="";F=(A=p>=xe-4&&p<=ye+4)&&w?y(E,R,T,C):A&&!w?"M ".concat(E,",").concat(R," L ").concat(f,",").concat(R," L ").concat(f,",").concat(C):!A&&w?"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C," L ").concat(T,",").concat(C):"M ".concat(f,",").concat(R," L ").concat(f,",").concat(C),de.push({id:m,pathD:F,style:v,leftIdx:e,rhsArrayIdx:j})}}),_e.current=ge}fe(de)}else fe([]),_e.current=[]}catch(e){console.error("Line render safe fail: ",e)}finally{Ve.current=!1}}},[qn,hn,gn,Se,Je,et,nt,z,Z,Hn,ce,on,an]),rt=t.useCallback(function(){var e,n,t,i,r,o,l,s,a,c,u,d,v,f,p=_e.current;if(p.length&&!he.current){var h=null!==(n=null===(e=Ye.current)||void 0===e?void 0:e.scrollTop)&&void 0!==n?n:0,g=null!==(i=null===(t=Le.current)||void 0===t?void 0:t.scrollTop)&&void 0!==i?i:0,x=null!==(o=null===(r=Ye.current)||void 0===r?void 0:r.clientHeight)&&void 0!==o?o:1/0,_=null!==(s=null===(l=Le.current)||void 0===l?void 0:l.clientHeight)&&void 0!==s?s:1/0,m=null!==(c=null===(a=Ye.current)||void 0===a?void 0:a.getBoundingClientRect().top)&&void 0!==c?c:0,b=null!==(d=null===(u=Le.current)||void 0===u?void 0:u.getBoundingClientRect().top)&&void 0!==d?d:0,S=m+x,R=b+_,C=null!==(f=null===(v=jn.current)||void 0===v?void 0:v.getBoundingClientRect().top)&&void 0!==f?f:0,I=function(e,n,t){return Math.max(n,Math.min(t,e))};p.forEach(function(e){var n=e.lhsScrollY-h+m,t=e.rhsScrollY-g+b,i=xe.current[e.styleId+"-stroke"],r=xe.current[e.styleId+"-bg"];if(i||r){var o,l=I(n,m,S),s=I(t,b,R),a=l-C,c=s-C,u=n>=m-4&&n<=S+4,d=t>=b-4&&t<=R+4,v=e.x1+.5*(e.x2-e.x1);o=u&&d?y(e.x1,a,e.x2,c):u&&!d?"M ".concat(e.x1,",").concat(a," L ").concat(v,",").concat(a," L ").concat(v,",").concat(c):!u&&d?"M ".concat(v,",").concat(a," L ").concat(v,",").concat(c," L ").concat(e.x2,",").concat(c):"M ".concat(v,",").concat(a," L ").concat(v,",").concat(c),i&&(i.setAttribute("visibility","visible"),i.setAttribute("d",o)),r&&(r.setAttribute("visibility","visible"),r.setAttribute("d",o))}})}},[]),ot=t.useRef(it);t.useEffect(function(){ot.current=it},[it]);var lt=t.useRef(null),st=t.useCallback(function(){null!==lt.current&&clearTimeout(lt.current),lt.current=setTimeout(function(){ot.current(),lt.current=null},50)},[]),at=t.useCallback(function(e){var n,t,i,r,o,l,s,a;if(!re.current){if(z||st(),ye.current){var c=be.current,u=En.current,d=Ye.current,v=Le.current;if(null!==c&&null!==u&&d&&v){var f="string"==typeof c?null===(n=Gn.current[c])||void 0===n?void 0:n.current:null===(t=bn.current[c])||void 0===t?void 0:t.current,p="string"==typeof u?null===(i=Xn.current[u])||void 0===i?void 0:i.current:null===(r=Jn.current[u])||void 0===r?void 0:r.current;if(f&&p){var h=f.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop,g=p.getBoundingClientRect().top-v.getBoundingClientRect().top+v.scrollTop;if(e.currentTarget===d){var x=g-(h-d.scrollTop),_=v.scrollHeight-v.clientHeight,m=Math.max(0,Math.min(x,_));Math.abs(v.scrollTop-m)>1&&(v.scrollTop=m)}else if(e.currentTarget===v){var y=h-(g-v.scrollTop),b=d.scrollHeight-d.clientHeight,S=Math.max(0,Math.min(y,b));Math.abs(d.scrollTop-S)>1&&(d.scrollTop=S)}if(Tn.current){var R=null===(o=Gn.current[c])||void 0===o?void 0:o.current,C=null===(l=Xn.current[u])||void 0===l?void 0:l.current,I=null!==(a=null===(s=jn.current)||void 0===s?void 0:s.getBoundingClientRect().top)&&void 0!==a?a:0,w=d.getBoundingClientRect().top,F=w+d.clientHeight,B=v.getBoundingClientRect().top,j=B+v.clientHeight,E=function(e,n,t){return Math.max(n,Math.min(t,e))};if(R&&C){var T=R.getBoundingClientRect(),A=C.getBoundingClientRect(),M=T.top+T.height/2,k=A.top+A.height/2,D=E(M,w,F),O=E(k,B,j);Tn.current.setAttribute("y1",(D-I).toString()),Tn.current.setAttribute("y2",(O-I).toString());var N=M>=w-4&&M<=F+4;Tn.current.setAttribute("visibility",N?"visible":"hidden")}}}}}_e.current.length>0&&!me.current&&(me.current=!0,requestAnimationFrame(function(){rt(),me.current=!1}))}},[rt,z,st]);t.useEffect(function(){var e=setTimeout(st,250);window.addEventListener("resize",st);var n=null,t=null;return Ne.current&&(n=new ResizeObserver(st)).observe(Ne.current),jn.current&&(t=new ResizeObserver(st)).observe(jn.current),function(){clearTimeout(e),window.removeEventListener("resize",st),null==n||n.disconnect(),null==t||t.disconnect()}},[Qe,un,_n,qn,on,an,hn,gn,Je,st,Z,Hn,te,ce]),t.useEffect(function(){ye.current=Z},[Z]),t.useEffect(function(){be.current=Hn},[Hn]);var ct=t.useCallback(function(){var e,n,t,i,r=De.sectionIdx,o=De.isOrphan;if(Ge(),null!=r)if(o)$("No counterpart exists for this section.");else if(Z&&Hn===r)Rn();else{if(!z){var l=be.current,s=En.current;if(null!==l){var a="string"==typeof l?null===(e=$n.current[l.split(_)[0]])||void 0===e?void 0:e.current:null===(n=Kn.current[l])||void 0===n?void 0:n.current;a&&(a.style.paddingTop="0px")}if(null!==s){var c="string"==typeof s?null===(t=Qn.current[s.split(_)[0]])||void 0===t?void 0:t.current:null===(i=Un.current[s])||void 0===i?void 0:i.current;c&&(c.style.paddingTop="0px")}}ue(new Set),fe([]),_e.current=[],G(!0),re.current=!0,Ln(r),be.current=r,ee(!0),ye.current=!0,ie(!1),We.current&&(We.current.style.height="0px"),ze.current&&(ze.current.style.height="0px"),Pe.current&&(Pe.current.style.height="0px"),qe.current&&(qe.current.style.height="0px"),requestAnimationFrame(function(){var e,n,t,i,o,l,s,a,c,u,d,v=null,f=null,p=null,h=null,g=null;if("string"==typeof r){v=(null===(e=Gn.current[r])||void 0===e?void 0:e.current)||null,g=(f=(null===(n=Xn.current[r])||void 0===n?void 0:n.current)||null)?r:null;var x=r.split(_)[0];p=(null===(t=$n.current[x])||void 0===t?void 0:t.current)||null,h=(null===(i=Qn.current[x])||void 0===i?void 0:i.current)||null}else if(v=(null===(o=bn.current[r])||void 0===o?void 0:o.current)||null,p=(null===(l=Kn.current[r])||void 0===l?void 0:l.current)||null,z){var m=hn[r],y=(null==m?void 0:m.refIndexes)||[];if(y.length>0){var b=y[0],S=gn.findIndex(function(e){return e.selfIndex===b});-1!==S&&(f=(null===(c=Jn.current[S])||void 0===c?void 0:c.current)||null,h=(null===(u=Un.current[S])||void 0===u?void 0:u.current)||null,g=S)}}else f=(null===(s=Jn.current[r])||void 0===s?void 0:s.current)||null,h=(null===(a=Un.current[r])||void 0===a?void 0:a.current)||null,g=f?r:null;En.current=g;var C=Ye.current,I=Le.current;if(!v||!C)return re.current=!1,void G(!1);if(!f||!I)return ie(!0),ot.current(),re.current=!1,void G(!1);if(!z){var w=v.getBoundingClientRect(),F=f.getBoundingClientRect(),B=w.top-F.top;p&&h&&(p.style.paddingTop="0px",h.style.paddingTop="0px",B>0?h.style.paddingTop="".concat(B,"px"):B<0&&(p.style.paddingTop="".concat(Math.abs(B),"px")));var j=v?v.getBoundingClientRect().top:(null==p?void 0:p.getBoundingClientRect().top)||0;return null===(d=Ne.current)||void 0===d||d.scrollTo({top:Ne.current.scrollTop+j-150,behavior:"smooth"}),ie(!0),ot.current(),re.current=!1,void G(!1)}var E=v.getBoundingClientRect().top-C.getBoundingClientRect().top+C.scrollTop,T=f.getBoundingClientRect().top-I.getBoundingClientRect().top+I.scrollTop-(E-C.scrollTop);T<0&&We.current&&(We.current.style.height="".concat(Math.abs(T),"px"));requestAnimationFrame(function(){var e,n=I.scrollHeight-I.clientHeight;if(T<0)e=0;else{if(T>n){var t=T-n;return ze.current&&(ze.current.style.height="".concat(t+150,"px")),void requestAnimationFrame(function(){R(I,T,200,function(){ie(!0),ot.current(),re.current=!1,G(!1)})})}e=T}R(I,e,200,function(){ie(!0),ot.current(),re.current=!1,G(!1)})})})}},[Ge,De.sectionIdx,Z,Hn,hn,gn,st,Rn]),ut=null!==De.sectionIdx&&ce.has(De.sectionIdx),dt=function(t){var o,l,s,c=t.section,u=t.idx,d=t.columnKey,v=t.colRef,f=t.mb,p=void 0===f?1:f,g=t.parentNodeId,x=void 0===g?"":g,_=z?!!on["".concat(d,"-").concat(u)]:!!on[String(u)],y=(null===(o=c.displayTitle)||void 0===o||o)&&a.hasValue(c.title),b=(null===(l=c.displayContent)||void 0===l||l)&&a.hasValue(c.content),S=!y&&!b,R={current:1},C=c.title;y||(C=b?"No Title Found":"No Matching Section Found");var I,w=[];if(null===(s=c.evaluationResult)||void 0===s?void 0:s.deviations){var F=c.evaluationResult.deviations;for(var B in F){var j=F[B][x];j&&w.push(j)}}return n.jsx(i.Box,e.__assign({ref:v,sx:{mb:p,width:"100%",display:"flex",flexDirection:"column",position:"relative",minWidth:0}},{children:n.jsxs(i.Accordion,e.__assign({disableGutters:!0,expanded:!S&&_,onChange:function(){return!S&&function(n,t){var i,r;he.current=!0,ge.current&&clearTimeout(ge.current),pe.current&&(pe.current.style.opacity="0");var o=null===(i=Kn.current[n])||void 0===i?void 0:i.current,l=null===(r=Un.current[n])||void 0===r?void 0:r.current;o&&(o.style.minHeight="0px"),l&&(l.style.minHeight="0px"),ge.current=setTimeout(function(){he.current=!1,ot.current(),pe.current&&(pe.current.style.opacity="1")},650),ln(function(i){var r=e.__assign({},i),o=z?"".concat(t,"-").concat(n):String(n),l=!i[o];if(!l){var s=String(Hn||""),a=Hn===n||s.startsWith("".concat(n,"-")),c=!1;ce.forEach(function(e){(e===n||String(e).startsWith("".concat(n,"-")))&&(c=!0)}),(a||c)&&(Rn(),ue(new Set),fe([]),_e.current=[])}if(!z)return r[String(n)]=l,r;if(r[o]=l,"left"===t)((null==(u=hn[n])?void 0:u.refIndexes)||[]).forEach(function(e){var n=gn.findIndex(function(n){return n.selfIndex===e});-1!==n&&(r["right-".concat(n)]=l)});else{var u,d=null==(u=gn[n])?void 0:u.selfIndex;hn.forEach(function(e,n){var t;(null===(t=e.refIndexes)||void 0===t?void 0:t.includes(d))&&(r["left-".concat(n)]=l)})}return r})}(u,d)},sx:{boxShadow:"none",border:S?"1px dashed #E2E8F0":"1px solid #E2E8F0",bgcolor:S?"#FAFAFA":"#FFFFFF",borderRadius:"6px",flexGrow:1,width:"100%",display:"flex",flexDirection:"column",minWidth:0,"&:before":{display:"none"}}},{children:[n.jsx(i.AccordionSummary,e.__assign({expandIcon:S?null:n.jsx(r.ChevronDown,{size:16}),sx:{minHeight:"36px",flexShrink:0,cursor:S?"default":"pointer","& .MuiAccordionSummary-content":{my:.5,display:"grid",alignItems:"center",minWidth:0,width:"100%"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:y&&n.jsx(i.Tooltip,e.__assign({title:C,placement:"top"},{children:n.jsx(i.Typography,e.__assign({component:"div",sx:{fontSize:"12px",color:S?"#94A3B8":"#19213D",fontWeight:S?400:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0}},{children:(I=C,I?a.safeStringify(I).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,t){return e.startsWith("**")&&e.endsWith("**")?n.jsx("strong",{children:e.slice(2,-2)},t):n.jsx(h.default.Fragment,{children:e},t)}):null)}))}))})),!S&&n.jsxs(i.AccordionDetails,e.__assign({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column",minWidth:0}},{children:[b&&n.jsx(m,{content:c.content,sxStyles:Ee,highlights:w,maintainRelativeOrder:z}),(c.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(u,"-").concat(n),depth:0,columnKey:d,parentNodeId:x,devCounter:R})})]}))]}))}),"".concat(d,"-sec-").concat(u))},vt=function(t){var o,l,s,c,u,d,v,f,p,g=t.section,x=t.keyPath,y=t.depth,b=void 0===y?0:y,S=t.columnKey,R=void 0===S?"left":S,C=t.parentNodeId,I=void 0===C?"":C,w=t.devCounter,F=void 0===w?{current:1}:w,B=(null===(o=g.displayTitle)||void 0===o||o)&&a.hasValue(g.title),j=(null===(l=g.displayContent)||void 0===l||l)&&a.hasValue(g.content),T=!B&&!j,A=B?g.title:j?"No Title Found":"No Matching Section Found",M=!!an[x];"left"!==R||$n.current[x]||($n.current[x]=h.default.createRef()),"right"!==R||Qn.current[x]||(Qn.current[x]=h.default.createRef());var k,D="left"===R?$n.current[x]:Qn.current[x],O=tt(x),N=x.split("-").map(Number),H=hn[N[0]];k=z&&void 0!==(null==H?void 0:H.selfIndex)&&H.selfIndex>=0?H.selfIndex+1:N[0]+1;for(var L=hn[N[0]],W=gn[N[0]],P=1;P<N.length;P++)(null==L?void 0:L.subsections)&&(L=L.subsections[N[P]]),(null==W?void 0:W.subsections)&&(W=W.subsections[N[P]]);var q=null===(s=null==E?void 0:E.input_index_map)||void 0===s?void 0:s[0],Y=null===(c=null==E?void 0:E.input_index_map)||void 0===c?void 0:c[1],V="left"===R?Y:q,K=z?!(null===(u=g.refIndexes)||void 0===u?void 0:u.length)||void 0!==g.selfIndex&&g.selfIndex<0:"left"===R?!W:!L,U=null!==(f=null===(v=null===(d=g.evaluationResult)||void 0===d?void 0:d.evaluation_outputs)||void 0===v?void 0:v.output_value)&&void 0!==f?f:null,G=Object.entries((null===(p=g.evaluationResult)||void 0===p?void 0:p.deviations)||{}).map(function(e){var n=e[0],t=e[1],i=F.current++,r=t[I],o="No equivalent clause present."===r;if(o)r="";else if(!r)return null;var l=function(e,n){return"".concat(e).concat(_).concat(n)}(x,n),s=t[V],a=K||!s||"No equivalent clause present."===s,c="".concat(k,".").concat(i);return"left"!==R||Gn.current[l]||(Gn.current[l]=h.default.createRef()),"right"!==R||Xn.current[l]||(Xn.current[l]=h.default.createRef()),{id:l,label:c,highlight:r,side:R,style:O,score:U,isConnected:ce.has(l),isOrphan:a,isMissingClause:o,badgeRef:"left"===R?Gn.current[l]:Xn.current[l],onClick:function(e){e.stopPropagation(),wn(e,L||{title:"",content:""},a,W||{title:"",content:""},l,O)}}}).filter(Boolean),X=G.some(function(e){return ce.has(e.id)});return B||j||g.subsections&&0!==g.subsections.length?B?n.jsx(i.Box,e.__assign({ref:D,sx:{mt:1,width:"100%",minWidth:0,position:"relative"}},{children:n.jsx(i.Box,e.__assign({sx:e.__assign({width:"100%"},X&&O&&{borderRadius:"4px",outline:"2px solid ".concat(O.badgeBorder),outlineOffset:"1px"})},{children:n.jsxs(i.Accordion,e.__assign({disableGutters:!0,expanded:!T&&M,onChange:function(){if(!T){if(M){var n=String(Hn||"").startsWith(x);n||ce.forEach(function(e){String(e).startsWith(x)&&(n=!0)}),n&&(Rn(),ue(new Set),fe([]),_e.current=[])}cn(function(n){var t;return e.__assign(e.__assign({},n),((t={})[x]=!n[x],t))})}},sx:{mt:0,boxShadow:"none",border:T?"1px dashed #E2E8F0":"1px solid #EEF2F7",borderRadius:"4px !important",bgcolor:"#FFFFFF",minWidth:0,"&:before":{display:"none"}}},{children:[n.jsx(i.AccordionSummary,e.__assign({expandIcon:T?null:n.jsx(r.ChevronDown,{size:14}),sx:{minHeight:"32px","& .MuiAccordionSummary-content":{my:.5,display:"grid",alignItems:"center",minWidth:0,width:"100%"}}},{children:n.jsx(i.Typography,e.__assign({component:"div",sx:{fontSize:"11px",fontWeight:600,color:T?"#94A3B8":"#19213D",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0}},{children:A||"Untitled Subsection"}))})),!T&&n.jsxs(i.AccordionDetails,e.__assign({sx:{pt:0,pb:1,minWidth:0}},{children:[j&&n.jsx(m,{content:g.content,sxStyles:Ee,deviationBadges:G,maintainRelativeOrder:z}),(g.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(x,"-").concat(n),depth:b+1,columnKey:R,parentNodeId:I,devCounter:F})})]}))]}))}))}),x):n.jsx(i.Box,e.__assign({ref:D,sx:{mt:0===b?1:.75,width:"100%",minWidth:0,position:"relative"}},{children:!T&&n.jsxs(i.Box,e.__assign({sx:e.__assign({width:"100%"},X&&O&&{borderRadius:"4px",outline:"2px solid ".concat(O.badgeBorder),outlineOffset:"1px"})},{children:[j&&n.jsx(m,{content:g.content,sxStyles:Ee,deviationBadges:G,maintainRelativeOrder:z}),(g.subsections||[]).map(function(e,n){return vt({section:e,keyPath:"".concat(x,"-").concat(n),depth:b+1,columnKey:R,parentNodeId:I,devCounter:F})})]}))}),x):null};return n.jsxs(i.Box,e.__assign({ref:He,sx:e.__assign(e.__assign({display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif'},z?{}:{overflow:"visible"}),{position:"relative"})},{children:[Y&&n.jsx(i.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(v.default,{})})),n.jsx(d.default,{open:De.open,anchorEl:De.anchorEl,sectionTitle:De.sectionTitle,referenceSectionTitle:De.refSectionTitle,onClose:Ge,onOpenCognitiveCompare:Fn,onOpenSideBySide:ct,onConnect:Bn,isConnected:ut,isOrphan:De.isOrphan}),Ae.open&&n.jsx(u.default,{open:Ae.open,popupRef:we,position:Ce,popupConfig:N,onClose:function(){Ie(null),Me(function(n){return e.__assign(e.__assign({},n),{open:!1})}),se(null)},markdownStyles:k,sectionTitle:Ae.sectionTitle,referenceSectionTitle:Ae.refSectionTitle,cognitiveData:Ae.cognitiveData,anchorEl:Ae.anchorEl,sectionAnchorEl:Ae.sectionAnchorEl,scrollContainerEl:Ne.current,badgeStyle:Ae.badgeStyle,docData:Ae.docData,deviationData:Ae.deviationData}),n.jsx(i.Snackbar,e.__assign({open:!!J,autoHideDuration:8e3,onClose:function(){return $(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(i.Alert,e.__assign({onClose:function(){return $(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:J}))})),(O.isHeaderVisible||O.isToggleVisible)&&n.jsxs(i.Box,e.__assign({sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:"#FFFFFF",border:"1.5px solid #EEF0F4",borderTopLeftRadius:"8px",borderTopRightRadius:"8px"}},{children:[n.jsx(i.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1}},{children:O.isHeaderVisible&&n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:600,color:"#0F172A"}},{children:j}))})),O.isToggleVisible&&n.jsx(i.Box,e.__assign({sx:{display:"flex",alignItems:"center"}},{children:n.jsx(i.FormControlLabel,{control:n.jsx(i.Switch,{checked:!z,onChange:function(e){var n=e.target.checked;V(!0),setTimeout(function(){P(!n),Rn(),ue(new Set),fe([]),_e.current=[],setTimeout(function(){V(!1)},400)},50)},color:"primary",size:"small",sx:{width:100,height:26,padding:0,"& .MuiSwitch-switchBase":{padding:0,margin:"3px",transitionDuration:"300ms","&.Mui-checked":{transform:"translateX(75px)",color:"#fff","& + .MuiSwitch-track":{backgroundColor:"#5928ED",opacity:1,border:0,"&::before":{content:'"Side by Side"',position:"absolute",left:"13px",top:"50%",transform:"translateY(-50%)",fontSize:"9px",fontWeight:700,color:"#fff",letterSpacing:"0.3px"}}}},"& .MuiSwitch-thumb":{boxSizing:"border-box",width:20,height:20},"& .MuiSwitch-track":{borderRadius:13,backgroundColor:"#9e9e9e",opacity:1,position:"relative","&::after":{content:'"Side by Side"',position:"absolute",right:"13px",top:"50%",transform:"translateY(-50%)",fontSize:"9px",fontWeight:700,color:"#fff",letterSpacing:"0.3px",opacity:1,transition:"opacity 0.2s"}},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{"&::after":{opacity:0}}}}),label:"",labelPlacement:"start",sx:{m:0,gap:1}})}))]})),n.jsx(i.Box,e.__assign({ref:Ne,onScroll:at,sx:{flex:1,minHeight:0,pt:1.5,pb:1,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",overflowY:z?"hidden":"auto",borderTop:mn&&yn?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(i.Box,e.__assign({sx:e.__assign({display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"},z?{flex:1,minHeight:0}:{})},{children:n.jsxs(i.Box,e.__assign({ref:jn,sx:e.__assign({display:"grid",gridTemplateColumns:"minmax(0, 1fr) 180px minmax(0, 1fr)",gap:"10px",maxWidth:"1200px",width:"100%",position:"relative",minHeight:0},z?{flex:1,overflow:"visible"}:{})},{children:[n.jsxs("svg",e.__assign({ref:pe,style:{position:"absolute",top:0,left:0,width:Be.width||"100%",height:Be.height||"100%",pointerEvents:"none",zIndex:10,overflow:"visible",transition:"opacity 0.15s ease-in-out"}},{children:[zn&&!Z&&n.jsxs("g",{children:[n.jsx("line",{x1:zn.x1,y1:zn.y,x2:Math.max(zn.x1,(zn.x1+zn.x2)/2-70),y2:zn.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),n.jsx("line",{x1:Math.min(zn.x2,(zn.x1+zn.x2)/2+70),y1:zn.y,x2:zn.x2,y2:zn.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),Dn.map(function(t){var l,s=t.x1+.5*(t.x2-t.x1),a=(t.y1+t.y2)/2;if("Not Defined"===t.style.label&&!t.hasCognitive)return null;var c=!1;if(t.isSubSection)c=Z&&Hn===t.subSectionKeyPath&&te;else{var u=hn[t.sectionIdx];(z?!(null===(l=null==u?void 0:u.refIndexes)||void 0===l?void 0:l.length)||(null==u?void 0:u.selfIndex)<0:!gn[t.sectionIdx])||(c=Z&&Hn===t.sectionIdx&&te)}if(c)return n.jsxs("g",e.__assign({style:{transition:"opacity 0.2s"}},{children:[n.jsx("defs",{children:n.jsx("marker",e.__assign({id:"arr-".concat(t.id),markerWidth:"7",markerHeight:"5",refX:"7",refY:"2.5",orient:"auto"},{children:n.jsx("polygon",{points:"0 0, 7 2.5, 0 5",fill:t.style.badgeBorder||"#6366F1"})}))}),n.jsx("line",{ref:Tn,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.badgeBorder||"#6366F1",strokeWidth:"1.5",markerEnd:"url(#arr-".concat(t.id,")")})]}),t.id);if(!z){var d=t.isSubSection?y(t.x1,t.y1,t.x2,t.y2):"M ".concat(t.x1," ").concat(t.y1," L ").concat(t.x2," ").concat(t.y2);return n.jsxs("g",{children:[n.jsx("path",{d:d,fill:"none",stroke:t.style.badgeBorder||"#E2E8F0",strokeWidth:"1.5"}),n.jsx("foreignObject",e.__assign({x:s-100,y:a-14,width:"200",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:n.jsx(i.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:n.jsxs(i.Box,e.__assign({onClick:function(e){if(e.stopPropagation(),Ae.open&&le===t.id)Ue();else{var n=hn[t.sectionIdx]||{title:"",content:""},i=gn[t.sectionIdx]||{title:"",content:""};if(t.isSubSection&&t.subSectionKeyPath){for(var r=t.subSectionKeyPath.split("-").map(Number),o=hn[r[0]],l=gn[r[0]],s=1;s<r.length;s++)(null==o?void 0:o.subsections)&&(o=o.subsections[r[s]]),(null==l?void 0:l.subsections)&&(l=l.subsections[r[s]]);o&&(n=o),l&&(i=l)}se(t.id),In(Cn(e.currentTarget,n,i,t.sectionIdx,t.style))}},sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:t.style.badgeBg,color:t.style.badgeText,border:"1px solid ".concat(t.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:600,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"}},{children:[0===t.style.label?"Same":t.style.label,n.jsx(i.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(o.ButtonCognitiveIcon,{})})),n.jsx(r.ChevronDown,{size:11,style:{transform:Ae.open&&le===t.id?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.25s ease"}})]}))}))}))]},t.id)}return null}),ve.map(function(t){var i,r=t.pathD,o=(null===(i=t.style)||void 0===i?void 0:i.badgeBorder)||"#6366F1",l="conn-marker-".concat(t.id),s="".concat(t.id,"-bg"),a="".concat(t.id,"-stroke");return n.jsxs("g",{children:[n.jsx("defs",{children:n.jsx("clipPath",e.__assign({id:"connections-clip"},{children:n.jsx("marker",e.__assign({id:l,markerWidth:"8",markerHeight:"6",refX:"7",refY:"3",orient:"auto"},{children:n.jsx("polygon",{points:"0 0, 8 3, 0 6",fill:o})}))}))}),n.jsx("path",{ref:function(e){xe.current[s]=e},d:r,fill:"none",stroke:"#FFFFFF",strokeWidth:"4",strokeOpacity:"0.7"}),n.jsx("path",{ref:function(e){xe.current[a]=e},d:r,fill:"none",stroke:o,strokeWidth:"1.75",markerEnd:"url(#".concat(l,")")})]},t.id)})]})),n.jsxs(i.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)"},z?{flex:1,overflow:"visible"}:{})},{children:[n.jsx(i.Box,e.__assign({ref:An,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E7E7E9",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"40px",alignItems:"center",overflowX:"hidden"}},{children:n.jsx(i.Tooltip,e.__assign({title:fn,placement:"top"},{children:n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center",textOverflow:"ellipsis",whiteSpace:"normal",width:"100%",height:"40px"}},{children:fn}))}))})),n.jsxs(i.Box,e.__assign({ref:Ye,onScroll:at,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},z?{maxHeight:"calc(100vh - 150px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,mr:"-160px",pr:"172px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:Pe,style:{width:"100%",height:"0px",flexShrink:0}}),xn&&hn.map(function(t,o){var l,s,a=!t.title&&!t.content;if(z&&a)return null;var c=t,u=nt(o),d=z?!(null===(l=c.refIndexes)||void 0===l?void 0:l.length)||c.selfIndex<0:!gn[o],v=z?"number"==typeof c.selfIndex&&c.selfIndex>=0?c.selfIndex+1:null:o+1,f=ce.has(o),p=function(e,n){var t,i,r,o,l,s;if(!e)return n;var a=null!==(s=null!==(o=null!==(i=null===(t=e.evaluation_output)||void 0===t?void 0:t.output_score)&&void 0!==i?i:null===(r=e.evaluation_outputs)||void 0===r?void 0:r.output_score)&&void 0!==o?o:null===(l=e.evaluation_outputs)||void 0===l?void 0:l.output_value)&&void 0!==s?s:e.output_score;return null!=a?a:n}(c.evaluationResult,null==u?void 0:u.deviationLabel);return n.jsx(i.Box,e.__assign({ref:Sn(o),sx:{mb:1,width:"100%"}},{children:n.jsxs(i.Box,e.__assign({sx:{position:"relative",width:"100%"}},{children:[n.jsx(i.Box,e.__assign({ref:Kn.current[o],sx:e.__assign({width:"100%",display:"flex"},f&&{borderRadius:"6px",outline:"2px solid ".concat((null==u?void 0:u.badgeBorder)||"#6366F1"),outlineOffset:"1px"})},{children:dt({section:t,idx:o,columnKey:"left",colRef:h.default.createRef(),mb:0,parentNodeId:(null===(s=null==E?void 0:E.input_index_map)||void 0===s?void 0:s[0])||""})})),z&&u&&n.jsxs(i.Box,e.__assign({ref:Gn.current[o],onClick:function(e){var n=z?gn.find(function(e){var n;return null===(n=c.refIndexes)||void 0===n?void 0:n.includes(e.selfIndex)})||{title:"",content:""}:gn[o]||{title:"",content:""};wn(e,t,d,n,o,u)},sx:{position:"absolute",top:"18px",right:0,transform:"translateY(-50%) translateX(calc(100% + 8px))",display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:u.badgeBg,color:u.badgeText,border:"1px solid ".concat(u.badgeBorder),borderRadius:"12px",px:1.2,py:.4,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",zIndex:20,boxShadow:"0 1px 3px rgba(0,0,0,0.07)"}},{children:[null!==v&&n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"11px",fontWeight:700,pr:.5,borderRight:"1px solid ".concat(u.badgeBorder)}},{children:v})),n.jsx(i.Box,e.__assign({component:"span",sx:{fontSize:"11px",px:.25}},{children:d?"No Deviation Found":"N/A"===p||"NA"===p?"N/A":0==p||null==p?"Same":"".concat(p)})),n.jsx(r.EllipsisVertical,{size:11,color:u.badgeText})]}))]}))}),"left-row-".concat(o))}),n.jsx("div",{ref:qe,style:{width:"100%",height:"0px",flexShrink:0}})]}))]})),n.jsx(i.Box,e.__assign({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"15px",gap:0}},{children:n.jsx(i.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(i.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:"5px",borderRadius:"20px",bgcolor:"#ECFDF3",border:"1px solid #A7F3D0",color:"#15803D",fontSize:"12px",fontWeight:600,whiteSpace:"nowrap",position:"relative",zIndex:1}},{children:[n.jsx(i.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(o.ButtonCognitiveIcon,{})})),0,"% Similarity",n.jsx(r.ChevronDown,{size:11})]}))}))})),n.jsxs(i.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},z?{flex:1,overflow:"visible",minHeight:0}:{})},{children:[U&&n.jsx(l.default,{sections:11}),n.jsx(i.Box,e.__assign({ref:Mn,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"40px",display:"flex",alignItems:"center",overflowX:"hidden"}},{children:n.jsx(i.Tooltip,e.__assign({title:pn,placement:"top"},{children:n.jsx(i.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",overflow:"hidden",display:"flex",justifyContent:"center",alignItems:"center",textOverflow:"ellipsis",whiteSpace:"normal",width:"100%",height:"40px"}},{children:pn}))}))})),n.jsxs(i.Box,e.__assign({ref:Le,onScroll:at,sx:e.__assign({p:"12px",display:"flex",flexDirection:"column"},z?{maxHeight:"calc(100vh - 150px)",flex:1,overflowY:"auto",overflowX:"hidden",minHeight:0,ml:"-25px",pl:"45px","&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"}:{})},{children:[n.jsx("div",{ref:We,style:{width:"100%",height:"0px",flexShrink:0}}),xn&&gn.map(function(t,r){var o,l=t,s=[],a=!1,c=null;if(z){s=hn.filter(function(e){var n;return(null===(n=e.refIndexes)||void 0===n?void 0:n.includes(l.selfIndex))&&e.selfIndex>=0}).map(function(e){return e.selfIndex+1});var u=hn.findIndex(function(e,n){var t;return ce.has(n)&&(null===(t=e.refIndexes)||void 0===t?void 0:t.includes(l.selfIndex))});(a=-1!==u)&&(c=nt(u))}else s=[r+1],(a=ce.has(r))&&(c=nt(r));return n.jsx(i.Box,e.__assign({ref:Jn.current[r],sx:{mb:1,width:"100%"}},{children:n.jsxs(i.Box,e.__assign({sx:{position:"relative",width:"100%"}},{children:[n.jsx(i.Box,e.__assign({ref:Un.current[r],sx:e.__assign({width:"100%",display:"flex"},a&&c&&{borderRadius:"6px",outline:"2px solid ".concat(c.badgeBorder),outlineOffset:"1px"})},{children:dt({section:t,idx:r,columnKey:"right",colRef:h.default.createRef(),mb:0,parentNodeId:(null===(o=null==E?void 0:E.input_index_map)||void 0===o?void 0:o[1])||""})})),z&&!U&&n.jsx(i.Box,e.__assign({ref:Xn.current[r],sx:{position:"absolute",top:"18px",left:0,transform:"translateY(-50%) translateX(calc(-100% - 8px))",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:"11px",bgcolor:"#EEF2FF",color:"#3730A3",border:"1px solid #C7D2FE",borderRadius:"10px",px:1,py:.3,fontWeight:700,whiteSpace:"nowrap",zIndex:20}},{children:s.length>0?s.join(", "):"-"}))]}))}),"right-row-".concat(r))}),n.jsx("div",{ref:ze,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 i=require("tslib"),o=require("react/jsx-runtime"),e=require("react"),n=require("@mui/material"),t=require("lucide-react"),s=require("react-dom"),a=require("../../assests/svg/SparkleIcon.js"),r=require("./CognitiveCompareConfig.js"),l=require("./CitationRenderer.js");function c(i){return i&&"object"==typeof i&&"default"in i?i:{default:i}}var d=c(s),x=10;exports.default=function(s){var c,p,g,u,v,h,b,f,_,m,y,F,j,w,k,B,S,C,D,E,T,I=s.open,R=s.onClose,A=s.sectionTitle,P=s.referenceSectionTitle,z=s.cognitiveData,L=s.relevanceScore,O=s.anchorEl,W=s.badgeStyle,q=s.popupRef,U=s.position,H=s.markdownStyles,M=s.docData,N=s.popupConfig,G=s.deviationData,Y=i.__assign(i.__assign({},r.SHARED_MARKDOWN_STYLES),H),K=e.useMemo(function(){var o,e;return i.__assign(i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG),N),{tabs:{deviation:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.tabs.deviation),null===(o=null==N?void 0:N.tabs)||void 0===o?void 0:o.deviation),association:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.tabs.association),null===(e=null==N?void 0:N.tabs)||void 0===e?void 0:e.association)},sectionTitles:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.sectionTitles),null==N?void 0:N.sectionTitles)})},[N]),X=null==z?void 0:z.isMissingRationale,J=e.useState(X?K.tabs.deviation.key:K.tabs.association.key),Q=J[0],V=J[1];e.useEffect(function(){I&&V(X?K.tabs.deviation.key:K.tabs.association.key)},[I,X,K.tabs.deviation.key,K.tabs.association.key]);var Z=e.useMemo(function(){if(!W)return{border:K.accentColor,shadow:"".concat(K.accentColor,"2E")};var i=W.badgeText;return"#9F1239"===i||"#B42318"===i?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===i?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===i?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:K.accentColor,shadow:"".concat(K.accentColor,"2E")}},[W,K.accentColor]);if(e.useEffect(function(){if(I){var i=function(i){var o;(null===(o=q.current)||void 0===o?void 0:o.contains(i.target))||(null==O?void 0:O.contains(i.target))||R()};return document.addEventListener("mousedown",i),function(){return document.removeEventListener("mousedown",i)}}},[I,R,O,q]),!I||!z)return null;var $=null!==(p=null!==(c=z.relevance_score)&&void 0!==c?c:L)&&void 0!==p?p:0,ii=z.decisioning,oi=Array.isArray(ii)?ii:"string"==typeof ii&&ii.trim()?[ii]:[],ei=z.gap,ni=Array.isArray(ei)?ei:"string"==typeof ei&&ei.trim()?[ei]:[],ti=null!==(g=null==U?void 0:U.arrowLeft)&&void 0!==g?g:60,si=o.jsxs(n.Box,i.__assign({ref:q,sx:{position:"fixed",top:null!==(u=null==U?void 0:U.top)&&void 0!==u?u:-9999,left:null!==(v=null==U?void 0:U.left)&&void 0!==v?v:-9999,zIndex:9999,width:"100%",maxWidth:"min(".concat(880,"px, calc(100vw - ").concat(null!==(h=null==U?void 0:U.left)&&void 0!==h?h:0,"px - ").concat(12,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat(Z.border),boxShadow:"0px 8px 32px ".concat(Z.shadow,", 0px 0px 0px 3px ").concat(Z.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:(null==U?void 0:U.maxHeight)?"min(60vh, ".concat(U.maxHeight,"px)"):"60vh",visibility:U?"visible":"hidden"}},{children:[U&&(U.openAbove?o.jsxs(o.Fragment,{children:[o.jsx(n.Box,{sx:{position:"absolute",bottom:-11,left:ti-x,width:0,height:0,borderLeft:"".concat(x,"px solid transparent"),borderRight:"".concat(x,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat(Z.border),zIndex:1}}),o.jsx(n.Box,{sx:{position:"absolute",bottom:-9,left:ti-x+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(x,"px solid #FFFFFF"),zIndex:2}})]}):o.jsxs(o.Fragment,{children:[o.jsx(n.Box,{sx:{position:"absolute",top:-11,left:ti-x,width:0,height:0,borderLeft:"".concat(x,"px solid transparent"),borderRight:"".concat(x,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat(Z.border),zIndex:1}}),o.jsx(n.Box,{sx:{position:"absolute",top:-9,left:ti-x+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(x,"px solid #FFFFFF"),zIndex:2}})]})),o.jsxs(n.Box,i.__assign({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[o.jsxs(n.Box,i.__assign({sx:{flex:1,minWidth:0}},{children:[o.jsxs(n.Typography,i.__assign({sx:{fontSize:"16px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden",width:"100%"}},{children:[o.jsx(n.Box,i.__assign({component:"span",title:A,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto",maxWidth:"calc(50% - 16px)",minWidth:0}},{children:A})),o.jsx(n.Box,i.__assign({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),o.jsx(n.Box,i.__assign({component:"span",title:P||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0}},{children:P||"Reference Section"}))]})),o.jsx(n.Box,i.__assign({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:null===(b=Object.values(K.tabs).find(function(i){return i.key===Q}))||void 0===b?void 0:b.subtitle}))}))]})),o.jsxs(n.Box,i.__assign({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[o.jsxs(n.Box,i.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:.5,borderRadius:"20px",bgcolor:"#FFFFFF",border:"1px solid #5928ED",fontSize:"12px",fontWeight:600,color:"#5928ED"}},{children:[o.jsx(a.default,{}),K.decisionStrengthLabel," ",$,"%"]})),o.jsx(n.IconButton,i.__assign({onClick:R,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:o.jsx(t.X,{size:22})}))]}))]})),o.jsx(n.Box,i.__assign({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:(X?[K.tabs.deviation]:[K.tabs.deviation,K.tabs.association]).map(function(e){var t=Q===e.key;return o.jsx(n.Box,i.__assign({onClick:function(){return V(e.key)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:t?600:400,color:t?K.accentColor:"#667085",backgroundColor:t?"".concat(K.accentColor,"14"):"transparent",borderBottom:t?"2px solid ".concat(K.accentColor):"2px solid transparent",transition:"all 0.15s",userSelect:"none"}},{children:e.label}),e.key)})})),o.jsx(n.Box,i.__assign({sx:{flex:1,minHeight:0,overflowY:"auto",px:2.5,py:2,display:"flex",flexDirection:"column",gap:1.5,"&::-webkit-scrollbar":{width:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"".concat(Z.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:Z.border},scrollbarWidth:"thin",scrollbarColor:"".concat(Z.border,"55 transparent")}},{children:Q===K.tabs.deviation.key?G?o.jsxs(o.Fragment,{children:[(null===(_=(null===(f=null==G?void 0:G.cognitive_decisioning)||void 0===f?void 0:f.decisioning_factors)||[])||void 0===_?void 0:_.length)>0&&o.jsx(l.default,{title:"Decision Making Factors",content:null===(y=null===(m=null==G?void 0:G.cognitive_decisioning)||void 0===m?void 0:m.decisioning_factors)||void 0===y?void 0:y.join("\n\n"),citations:null===(F=null==G?void 0:G.cognitive_decisioning)||void 0===F?void 0:F.citations,styles:Y,docData:M,open:I}),(null===(w=(null===(j=null==G?void 0:G.cognitive_decisioning)||void 0===j?void 0:j.gaps_in_decision)||[])||void 0===w?void 0:w.length)>0&&o.jsx(l.default,{title:"Gaps in Decision",content:null===(B=null===(k=null==G?void 0:G.cognitive_decisioning)||void 0===k?void 0:k.gaps_in_decision)||void 0===B?void 0:B.join("\n\n"),citations:null===(S=null==G?void 0:G.cognitive_decisioning)||void 0===S?void 0:S.citations,styles:Y,docData:M,open:I}),0===(null===(D=(null===(C=null==G?void 0:G.cognitive_decisioning)||void 0===C?void 0:C.decisioning_factors)||[])||void 0===D?void 0:D.length)&&0===(null===(T=(null===(E=null==G?void 0:G.cognitive_decisioning)||void 0===E?void 0:E.gaps_in_decision)||[])||void 0===T?void 0:T.length)&&o.jsx(n.Box,i.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]}):o.jsx(l.default,{title:"Deviation Analysis",content:"Deviation analysis content will appear here. This tab shows\n structural and semantic deviations identified between the two\n sections being compared.",citations:{},styles:Y,docData:M,open:I}):o.jsxs(o.Fragment,{children:[oi.length>0&&o.jsx(l.default,{title:K.sectionTitles.decisioningFactors,content:oi.join("\n\n"),citations:z.citations,styles:Y,open:I,docData:M}),ni.length>0&&o.jsx(l.default,{title:K.sectionTitles.gaps,content:ni.join("\n\n"),citations:z.citations,styles:Y,open:I,docData:M}),0===oi.length&&0===ni.length&&o.jsx(n.Box,i.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:K.emptyStateMessage}))}))]})}))]}));return d.default.createPortal(si,document.body)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("tslib"),o=require("react/jsx-runtime"),e=require("react"),n=require("@mui/material"),t=require("lucide-react"),s=require("react-dom"),a=require("../../assests/svg/SparkleIcon.js"),r=require("./CognitiveCompareConfig.js"),l=require("./CitationRenderer.js");function d(i){return i&&"object"==typeof i&&"default"in i?i:{default:i}}var c=d(s),x=10;exports.default=function(s){var d,p,g,u,v,h,b,f,_,m,y,F,j,w,k,B,S,C,D,E,T,I,R=s.open,A=s.onClose,P=s.sectionTitle,z=s.referenceSectionTitle,L=s.cognitiveData,O=s.relevanceScore,W=s.anchorEl,q=s.badgeStyle,U=s.popupRef,H=s.position,M=s.markdownStyles,N=s.docData,G=s.popupConfig,Y=s.deviationData,K=i.__assign(i.__assign({},r.SHARED_MARKDOWN_STYLES),M),X=e.useMemo(function(){var o,e;return i.__assign(i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG),G),{tabs:{deviation:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.tabs.deviation),null===(o=null==G?void 0:G.tabs)||void 0===o?void 0:o.deviation),association:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.tabs.association),null===(e=null==G?void 0:G.tabs)||void 0===e?void 0:e.association)},sectionTitles:i.__assign(i.__assign({},r.DEFAULT_POPUP_CONFIG.sectionTitles),null==G?void 0:G.sectionTitles)})},[G]),J=null==L?void 0:L.isMissingRationale,Q=e.useState(J?X.tabs.deviation.key:X.tabs.association.key),V=Q[0],Z=Q[1];e.useEffect(function(){R&&Z(J?X.tabs.deviation.key:X.tabs.association.key)},[R,J,X.tabs.deviation.key,X.tabs.association.key]);var $=e.useMemo(function(){if(!q)return{border:X.accentColor,shadow:"".concat(X.accentColor,"2E")};var i=q.badgeText;return"#9F1239"===i||"#B42318"===i?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===i?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===i?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:X.accentColor,shadow:"".concat(X.accentColor,"2E")}},[q,X.accentColor]);if(e.useEffect(function(){if(R){var i=function(i){var o;(null===(o=U.current)||void 0===o?void 0:o.contains(i.target))||(null==W?void 0:W.contains(i.target))||A()};return document.addEventListener("mousedown",i),function(){return document.removeEventListener("mousedown",i)}}},[R,A,W,U]),!R||!L)return null;var ii=null!==(g=null!==(p=V===X.tabs.deviation.key?null===(d=null==Y?void 0:Y.cognitive_decisioning)||void 0===d?void 0:d.decision_strength:L.relevance_score)&&void 0!==p?p:O)&&void 0!==g?g:0,oi=L.decisioning,ei=Array.isArray(oi)?oi:"string"==typeof oi&&oi.trim()?[oi]:[],ni=L.gap,ti=Array.isArray(ni)?ni:"string"==typeof ni&&ni.trim()?[ni]:[],si=null!==(u=null==H?void 0:H.arrowLeft)&&void 0!==u?u:60,ai=o.jsxs(n.Box,i.__assign({ref:U,sx:{position:"fixed",top:null!==(v=null==H?void 0:H.top)&&void 0!==v?v:-9999,left:null!==(h=null==H?void 0:H.left)&&void 0!==h?h:-9999,zIndex:9999,width:"100%",maxWidth:"min(".concat(880,"px, calc(100vw - ").concat(null!==(b=null==H?void 0:H.left)&&void 0!==b?b:0,"px - ").concat(12,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat($.border),boxShadow:"0px 8px 32px ".concat($.shadow,", 0px 0px 0px 3px ").concat($.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:(null==H?void 0:H.maxHeight)?"min(60vh, ".concat(H.maxHeight,"px)"):"60vh",visibility:H?"visible":"hidden"}},{children:[H&&(H.openAbove?o.jsxs(o.Fragment,{children:[o.jsx(n.Box,{sx:{position:"absolute",bottom:-11,left:si-x,width:0,height:0,borderLeft:"".concat(x,"px solid transparent"),borderRight:"".concat(x,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat($.border),zIndex:1}}),o.jsx(n.Box,{sx:{position:"absolute",bottom:-9,left:si-x+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(x,"px solid #FFFFFF"),zIndex:2}})]}):o.jsxs(o.Fragment,{children:[o.jsx(n.Box,{sx:{position:"absolute",top:-11,left:si-x,width:0,height:0,borderLeft:"".concat(x,"px solid transparent"),borderRight:"".concat(x,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat($.border),zIndex:1}}),o.jsx(n.Box,{sx:{position:"absolute",top:-9,left:si-x+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(x,"px solid #FFFFFF"),zIndex:2}})]})),o.jsxs(n.Box,i.__assign({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[o.jsxs(n.Box,i.__assign({sx:{flex:1,minWidth:0}},{children:[("no title"!==P||"no title"!==z)&&o.jsxs(n.Typography,i.__assign({sx:{fontSize:"16px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden",width:"100%"}},{children:[o.jsx(n.Box,i.__assign({component:"span",title:P,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto",maxWidth:"calc(50% - 16px)",minWidth:0}},{children:P})),o.jsx(n.Box,i.__assign({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),o.jsx(n.Box,i.__assign({component:"span",title:z||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0}},{children:z||"Reference Section"}))]})),o.jsx(n.Box,i.__assign({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:null===(f=Object.values(X.tabs).find(function(i){return i.key===V}))||void 0===f?void 0:f.subtitle}))}))]})),o.jsxs(n.Box,i.__assign({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[o.jsxs(n.Box,i.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"5px",px:1.5,py:.5,borderRadius:"20px",bgcolor:"#FFFFFF",border:"1px solid #5928ED",fontSize:"12px",fontWeight:600,color:"#5928ED"}},{children:[o.jsx(a.default,{}),X.decisionStrengthLabel," ",ii,"%"]})),o.jsx(n.IconButton,i.__assign({onClick:A,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:o.jsx(t.X,{size:22})}))]}))]})),o.jsx(n.Box,i.__assign({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:(J?[X.tabs.deviation]:[X.tabs.deviation,X.tabs.association]).map(function(e){var t=V===e.key;return o.jsx(n.Box,i.__assign({onClick:function(){return Z(e.key)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:t?600:400,color:t?X.accentColor:"#667085",backgroundColor:t?"".concat(X.accentColor,"14"):"transparent",borderBottom:t?"2px solid ".concat(X.accentColor):"2px solid transparent",transition:"all 0.15s",userSelect:"none"}},{children:e.label}),e.key)})})),o.jsx(n.Box,i.__assign({sx:{flex:1,minHeight:0,overflowY:"auto",px:2.5,py:2,display:"flex",flexDirection:"column",gap:1.5,"&::-webkit-scrollbar":{width:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"".concat($.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:$.border},scrollbarWidth:"thin",scrollbarColor:"".concat($.border,"55 transparent")}},{children:V===X.tabs.deviation.key?Y?o.jsxs(o.Fragment,{children:[(null===(m=(null===(_=null==Y?void 0:Y.cognitive_decisioning)||void 0===_?void 0:_.decisioning_factors)||[])||void 0===m?void 0:m.length)>0&&o.jsx(l.default,{title:"Decision Making Factors",content:null===(F=null===(y=null==Y?void 0:Y.cognitive_decisioning)||void 0===y?void 0:y.decisioning_factors)||void 0===F?void 0:F.join("\n\n"),citations:null===(j=null==Y?void 0:Y.cognitive_decisioning)||void 0===j?void 0:j.citations,styles:K,docData:N,open:R}),(null===(k=(null===(w=null==Y?void 0:Y.cognitive_decisioning)||void 0===w?void 0:w.gaps_in_decision)||[])||void 0===k?void 0:k.length)>0&&o.jsx(l.default,{title:"Gaps in Decision",content:null===(S=null===(B=null==Y?void 0:Y.cognitive_decisioning)||void 0===B?void 0:B.gaps_in_decision)||void 0===S?void 0:S.join("\n\n"),citations:null===(C=null==Y?void 0:Y.cognitive_decisioning)||void 0===C?void 0:C.citations,styles:K,docData:N,open:R}),0===(null===(E=(null===(D=null==Y?void 0:Y.cognitive_decisioning)||void 0===D?void 0:D.decisioning_factors)||[])||void 0===E?void 0:E.length)&&0===(null===(I=(null===(T=null==Y?void 0:Y.cognitive_decisioning)||void 0===T?void 0:T.gaps_in_decision)||[])||void 0===I?void 0:I.length)&&o.jsx(n.Box,i.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]}):o.jsx(l.default,{title:"Deviation Analysis",content:"Deviation analysis content will appear here. This tab shows\n structural and semantic deviations identified between the two\n sections being compared.",citations:{},styles:K,docData:N,open:R}):o.jsxs(o.Fragment,{children:[ei.length>0&&o.jsx(l.default,{title:X.sectionTitles.decisioningFactors,content:ei.join("\n\n"),citations:L.citations,styles:K,open:R,docData:N}),ti.length>0&&o.jsx(l.default,{title:X.sectionTitles.gaps,content:ti.join("\n\n"),citations:L.citations,styles:K,open:R,docData:N}),0===ei.length&&0===ti.length&&o.jsx(n.Box,i.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:o.jsx(n.Typography,i.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:X.emptyStateMessage}))}))]})}))]}));return c.default.createPortal(ai,document.body)};
2
2
  //# sourceMappingURL=CognitivePopup.js.map