@viswa-test/test-citation 0.0.14 → 0.0.17

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"),i=require("react"),t=require("@mui/material"),r=require("lucide-react"),o=require("react-dom"),s=require("../../assests/svg/SparkleIcon.js"),l=require("../../assests/svg/ButtonCognitiveIcon.js"),a=require("react-markdown");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(i),u=c(o),x=c(a),g=function(e){return null==e?"":"string"==typeof e?e:Array.isArray(e)?e.map(g).join("\n\n"):"object"==typeof e?JSON.stringify(e):String(e)},p=function(e){return e?g(e).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,i){return e.startsWith("**")&&e.endsWith("**")?n.jsx("strong",{children:e.slice(2,-2)},i):n.jsx(d.default.Fragment,{children:e},i)}):null},h=function(n,i,t,r){var o=100*(n||0),s=r.thresholds,l=r.relationStyles;if(!t)return null;var a=function(e){return e&&"string"==typeof e?e.split("_").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}).join(" "):"Unknown"}(i),c=(i||"").toLowerCase();return c.includes("no_deviation")?e.__assign(e.__assign({},l.low),{label:a}):c.includes("deviation")||c.includes("high_risk")||c.includes("critical")?e.__assign(e.__assign({},l.high),{label:a}):o>=s.exact?e.__assign(e.__assign({},l.exact),{label:a}):o>=s.high?e.__assign(e.__assign({},l.high),{label:a}):o>=s.medium?e.__assign(e.__assign({},l.medium),{label:a}):e.__assign(e.__assign({},l.low),{label:a})},f=d.default.forwardRef(function(i,r){var o=i.label,s=i.content,l=i.highlights,a=void 0===l?[]:l,c=i.styleVariant,u=i.isHighlighted,x=void 0!==u&&u,h=Array.isArray(s)?s.map(g).join("\n"):g(s),f="#9F1239"===c.badgeText?{borderColor:"#E11D48",shadow:"rgba(225, 29, 72, 0.25)"}:"#B91C1C"===c.badgeText?{borderColor:"#EF4444",shadow:"rgba(239, 68, 68, 0.25)"}:"#1D4ED8"===c.badgeText?{borderColor:"#3B82F6",shadow:"rgba(59, 130, 246, 0.25)"}:"#A16207"===c.badgeText?{borderColor:"#F59E0B",shadow:"rgba(245, 158, 11, 0.25)"}:{borderColor:"#6366F1",shadow:"rgba(99, 102, 241, 0.25)"};return n.jsxs(t.Box,e.__assign({sx:{mb:1.5}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"12px",color:"#19213D",mb:.5,fontWeight:500}},{children:o})),n.jsx(t.Box,e.__assign({ref:r,sx:{p:"4px 12px",borderRadius:"6px",border:x?"1.5px solid ".concat(f.borderColor):"1px solid ".concat(c.border),boxShadow:x?"0px 0px 0px 2px ".concat(f.shadow):"none",bgcolor:c.bg,fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,minHeight:"24px",display:"flex",alignItems:"center",whiteSpace:"pre-line",wordBreak:"break-word"}},{children:n.jsx(t.Box,{children:function(){if(!h)return null;if(!a||0===a.length)return p(h);var i=a.filter(function(e){return e&&"string"==typeof e&&e.length>0}).map(function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")});if(0===i.length)return p(h);var r=new RegExp("(".concat(i.join("|"),")"),"gi");return h.split(r).map(function(i,r){return a.some(function(e){return e&&"string"==typeof e&&e.toLowerCase()===i.toLowerCase()})?n.jsx(t.Box,e.__assign({component:"span",sx:{bgcolor:c.highlightBg,borderRadius:"2px",px:"2px"}},{children:p(i)}),r):n.jsx(d.default.Fragment,{children:p(i)},r)})}()})}))]}))}),v=10,_=function(o){var l,a,c,d,x,p,h,f=o.open,_=o.onClose,m=o.sectionTitle,b=o.referenceSectionTitle,y=o.cognitiveData,F=o.relevanceScore,w=o.anchorEl,B=o.badgeStyle,j=o.popupRef,E=o.position,S=i.useState("association"),C=S[0],D=S[1],k=i.useMemo(function(){if(!B)return{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"};var e=B.badgeText;return"#9F1239"===e||"#B42318"===e?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===e?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===e?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"}},[B]);if(i.useEffect(function(){if(f){var e=function(e){var n;(null===(n=j.current)||void 0===n?void 0:n.contains(e.target))||(null==w?void 0:w.contains(e.target))||_()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[f,_,w,j]),!f||!y)return null;var A=null!==(a=null!==(l=y.relevance_score)&&void 0!==l?l:F)&&void 0!==a?a:0,R=function(e){return e?e.split(/(?<=\.)(?:\s+(?=[A-Z])|\s+\d+\.\s)/).map(function(e){return e.trim()}).filter(function(e){return e.length>10}):[]},T=R(null!==(c=y.decisioning)&&void 0!==c?c:""),I=R(null!==(d=y.gap)&&void 0!==d?d:""),z=function(e){if(!e)return[];if(Array.isArray(e))return e.flatMap(function(e){if("string"==typeof e)return[{key:"metadata",value:e}];if("object"==typeof e&&null!==e){var n=e,i={key:g(n.key),value:g(n.value),url:g(n.url)};return i.value||i.key||i.url?[i]:[]}return[]});if("string"==typeof e)return[{key:"metadata",value:e}];if("object"==typeof e){var n=e;if("value"in n||"key"in n||"url"in n)return[{key:g(n.key),value:g(n.value),url:g(n.url)}]}return[]},W=function(e,n){var i,t,r=y,o="decisioning"===e?null!==(i=r.decisioning_metadata)&&void 0!==i?i:r.decisioningMetadata:null!==(t=r.gap_metadata)&&void 0!==t?t:r.gapMetadata;if(Array.isArray(o)){if((d=z(o[n])).length)return d;if((u=z(o)).length)return u}else{var s=z(o);if(s.length)return s}var l=r.metadata;if(l&&"object"==typeof l&&!Array.isArray(l)){var a=l,c="decisioning"===e?a.decisioning:a.gap;if(Array.isArray(c)){var d,u;if((d=z(c[n])).length)return d;if((u=z(c)).length)return u}else{var x=z(c);if(x.length)return x}}return[]},L=function(i){if(!i.length)return null;var o=i[0],s=o.key||"metadata",l=o.value||o.url||"",a=l?"".concat(s,": ").concat(l):s;return n.jsxs(t.Box,e.__assign({component:"span",sx:{display:"inline-flex",alignItems:"center",color:"#253AE4",fontWeight:600,ml:.5,whiteSpace:"nowrap"}},{children:["(",a,n.jsx(r.ChevronDown,{size:13,style:{marginLeft:2}}),")"]}))},H=null!==(x=null==E?void 0:E.arrowLeft)&&void 0!==x?x:60,M=n.jsxs(t.Box,e.__assign({ref:j,sx:{position:"fixed",top:null!==(p=null==E?void 0:E.top)&&void 0!==p?p:-9999,left:null!==(h=null==E?void 0:E.left)&&void 0!==h?h:-9999,zIndex:9999,width:"min(".concat(680,"px, calc(100vw - ").concat(24,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat(k.border),boxShadow:"0px 8px 32px ".concat(k.shadow,", 0px 0px 0px 3px ").concat(k.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:"60vh",visibility:E?"visible":"hidden"}},{children:[E&&(E.openAbove?n.jsxs(n.Fragment,{children:[n.jsx(t.Box,{sx:{position:"absolute",bottom:-11,left:H-v,width:0,height:0,borderLeft:"".concat(v,"px solid transparent"),borderRight:"".concat(v,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat(k.border),zIndex:1}}),n.jsx(t.Box,{sx:{position:"absolute",bottom:-9,left:H-v+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(v,"px solid #FFFFFF"),zIndex:2}})]}):n.jsxs(n.Fragment,{children:[n.jsx(t.Box,{sx:{position:"absolute",top:-11,left:H-v,width:0,height:0,borderLeft:"".concat(v,"px solid transparent"),borderRight:"".concat(v,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat(k.border),zIndex:1}}),n.jsx(t.Box,{sx:{position:"absolute",top:-9,left:H-v+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(v,"px solid #FFFFFF"),zIndex:2}})]})),n.jsxs(t.Box,e.__assign({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[n.jsxs(t.Box,e.__assign({sx:{flex:1,minWidth:0}},{children:[n.jsxs(t.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden"}},{children:[n.jsx(t.Box,e.__assign({component:"span",title:m,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:m})),n.jsx(t.Box,e.__assign({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),n.jsx(t.Box,e.__assign({component:"span",title:b||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:b||"Reference Section"}))]})),n.jsx(t.Box,e.__assign({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:"Why this is a Deviation?"}))}))]})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[n.jsxs(t.Box,e.__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:[n.jsx(s.default,{}),"Decision Strength ",A,"%"]})),n.jsx(t.IconButton,e.__assign({onClick:_,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:n.jsx(r.X,{size:22})}))]}))]})),n.jsx(t.Box,e.__assign({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:["deviation","association"].map(function(i){var r=C===i,o="deviation"===i?"Deviation Analysis":"Association Logic";return n.jsx(t.Box,e.__assign({onClick:function(){return D(i)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:r?600:400,color:r?"#5928ED":"#667085",backgroundColor:r?"rgba(89,40,237,0.08)":"transparent",borderBottom:r?"2px solid #5928ED":"2px solid transparent",transition:"all 0.15s",userSelect:"none",overflowY:"auto"}},{children:o}),i)})})),n.jsx(t.Box,e.__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(k.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:k.border},scrollbarWidth:"thin",scrollbarColor:"".concat(k.border,"55 transparent")}},{children:"deviation"===C?n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD",p:2,display:"flex",flexDirection:"column",gap:1}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054"}},{children:"Deviation Analysis"})),n.jsx(t.Typography,e.__assign({sx:{fontSize:"14px",color:"#667085",lineHeight:1.6}},{children:"Deviation analysis content will appear here. This tab shows structural and semantic deviations identified between the two sections being compared."}))]})):n.jsxs(n.Fragment,{children:[T.length>0&&n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[n.jsx(t.Box,e.__assign({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Decision Making Factors"}))})),n.jsx(t.Box,e.__assign({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:T.map(function(i,r){return n.jsxs(t.Typography,e.__assign({sx:{fontSize:"14px",color:"#344054",lineHeight:1.55,wordBreak:"break-word"}},{children:[r+1,". ",i,L(W("decisioning",r))]}),r)})}))]})),I.length>0&&n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[n.jsx(t.Box,e.__assign({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Gaps in Decision"}))})),n.jsx(t.Box,e.__assign({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:I.map(function(i,r){return n.jsxs(t.Typography,e.__assign({sx:{fontSize:"14px",color:"#344054",lineHeight:1.55,wordBreak:"break-word"}},{children:[r+1,". ",i,L(W("gap",r))]}),r)})}))]})),0===T.length&&0===I.length&&n.jsx(t.Box,e.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]})}))]}));return u.default.createPortal(M,document.body)},m=function(i){var o=i.data,s=i.isSelected,a=i.isCognitiveOpen,c=i.onToggleCognitive,d=i.onClick,u=g(o.summaryText||o.description),x=u.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),p=x?u.replace(x[0],"").trim():u,h=!!x;return n.jsxs(t.Box,e.__assign({id:"variant-card-".concat(o.id),onClick:d,sx:{minWidth:"280px",maxWidth:"280px",p:2,m:.5,bgcolor:s?"#EFF6FF99":"#FFFFFF",borderRadius:"8px",cursor:"pointer",transition:"all 0.2s",display:"flex",flexDirection:"column",gap:1,flexShrink:0,opacity:o.isLoading?.7:1,border:s?"1.4px solid #2563EB":void 0,boxShadow:s?"none":"0px 2px 4px 0px #19213D14","&:hover":{borderColor:s?"#2563EB":"#CBD5E1",boxShadow:s?"none":"0px 4px 8px 0px #19213D1F"}}},{children:[n.jsx(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1.5}},{children:o.isLoading?n.jsx(t.Skeleton,{variant:"rounded",width:80,height:20}):n.jsxs(t.Box,e.__assign({sx:{bgcolor:"#FEF2F2",color:"#B91C1C",fontSize:"11px",fontWeight:600,px:1,py:.5,borderRadius:"100px",border:"1px solid #FFE1E1"}},{children:[void 0!==o.similarity?o.similarity:0,"% Similarity"]}))})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:1}},{children:[n.jsx(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontWeight:500,fontSize:"14px",color:"#19213D",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"}},{children:g(o.title)}))})),o.isLoading?n.jsxs(t.Box,{children:[n.jsx(t.Skeleton,{width:"90%"}),n.jsx(t.Skeleton,{width:"60%"})]}):n.jsxs(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontWeight:400,fontSize:"13px",color:"#666F8D",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"}},{children:p})),h&&n.jsxs(t.Box,e.__assign({onClick:function(e){e.stopPropagation(),s||d(),c()},sx:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",cursor:"pointer",marginLeft:"-4px","&:hover":{backgroundColor:"#F1F5F9"}}},{children:[n.jsx("div",e.__assign({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:n.jsx(l.ButtonCognitiveIcon,{})})),n.jsx(r.ChevronDown,{size:12,style:{transform:s&&a?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}))]}))]}))]}))},b=[{key:"title",label:"Title",analysisKey:"title"},{key:"description",label:"Description",analysisKey:"description"}],y={fields:b,thresholds:{exact:90,high:70,medium:40},relationStyles:{noContent:{bg:"#FFFFFF",border:"#E2E8F0",badgeBg:"#F8FAFC",badgeBorder:"#F1F5F9",badgeText:"#64748B",highlightBg:"transparent"},exact:{bg:"#FFF1F2",border:"#FECDD3",badgeBg:"#FFE4E6",badgeBorder:"#FEE2E2",badgeText:"#9F1239",highlightBg:"#FECDD3"},high:{bg:"#FFF5F5",border:"#FECACA",badgeBg:"#FEECEC",badgeBorder:"#F8C2C2",badgeText:"#B42318",highlightBg:"#FDD5D5"},medium:{bg:"#FFFCF6",border:"#FFDD80",badgeBg:"#FEF9C3",badgeBorder:"#FEF08A",badgeText:"#A16207",highlightBg:"#FDDEB3"},low:{bg:"#F5F9FF",border:"#CFE0FF",badgeBg:"#EEF4FF",badgeBorder:"#BFD3FF",badgeText:"#1D4ED8",highlightBg:"#DCEAFF"}}},F=function(e){return null!=e&&("string"==typeof e?e.trim().length>0:!Array.isArray(e)||e.length>0&&e.some(function(e){return F(e)}))},w=function(n){var i,t,r,o,s=[],l=[],a=n.base_root_id,c=n.input_index_map||{0:"left",1:"right"},d=n[a];if(!d||!1===d.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var u=function(e,n){var i,t=c[n],r=null===(i=null==e?void 0:e.comparison_inputs)||void 0===i?void 0:i[t];return{title:g((null==r?void 0:r.title)||""),content:g((null==r?void 0:r.content)||"")}};d.next&&Object.values(d.next).forEach(function(i){var t=n[i];if(t&&!1!==t.display_node){var r=function(e){if(!e.mapping_rationale)return{score:void 0,relation:"not_defined"};var n=e.mapping_rationale,i=!n.decision_strength,t=parseInt(n.decision_strength||"0");return{cognitiveData:{decisioning:n.decisioning_factors||"",gap:n.gaps_in_decision||"",relevance_score:t},score:i?100:t/100,relation:t>=70?"no_deviation":"deviation"}}(t),o=u(t,"0"),a=u(t,"1"),c=e.__assign({id:i,title:o.title,content:o.content,subsections:[]},r),d=e.__assign({id:i,title:a.title,content:a.content,subsections:[]},r);if(t.next)Object.values(t.next).forEach(function(e){var i=n[e];if(i&&!1!==i.display_node){var t=u(i,"0"),r=u(i,"1");t.content&&c.subsections.push(t.content),r.content&&d.subsections.push(r.content)}});s.push(c),l.push(d)}});return{activeProposed:{title:(null===(t=null===(i=d.comparison_inputs)||void 0===i?void 0:i[c[0]])||void 0===t?void 0:t.title)||"Uploaded Contract",description:d.decision_scope_description||"",sections:s},activeVariants:[{id:"tree-variant-1",title:(null===(o=null===(r=d.comparison_inputs)||void 0===r?void 0:r[c[1]])||void 0===o?void 0:o.title)||"Reference Template",similarity:0,sections:l,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:d.decision_scope_description||""},fields:{}}}}]}};exports.DEFAULT_COMPARISON_CONFIG=y,exports.DEFAULT_FIELD_CONFIG=b,exports.default=function(o){var s,a,c,u=o.variants,B=void 0===u?[]:u,j=o.treeData,E=o.comparisonConfig,S=o.onSelectVariant;o.onSkip,o.onBack;var C=o.targetVariantId,D=o.highlightedField;o.onBadgeClick,o.activeBadgeId;var k=i.useState(null),A=k[0],R=k[1],T=i.useMemo(function(){return(null==j?void 0:j.cognitive_decisioning)||{}},[j]),I=i.useRef(null),z=i.useState(null),W=z[0],L=z[1],H=i.useRef(null),M=i.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null}),O=M[0],P=M[1],q=i.useRef(null),V=i.useRef(null),N=i.useRef(null),U=i.useRef(!1),K=i.useCallback(function(){var e;if(O.anchorEl&&O.refSectionTitle){var n=O.anchorEl.getBoundingClientRect(),i=(null===(e=null==H?void 0:H.current)||void 0===e?void 0:e.offsetHeight)||0,t=Math.min(680,window.innerWidth-24),r=window.innerHeight-n.bottom-12,o=n.top-12,s=r<i&&o>r,l=s?n.top-12-i:n.bottom+12,a=n.left+n.width/2,c=a-t/2,d=Math.max(12,Math.min(c,window.innerWidth-t-12)),u=Math.max(14,Math.min(a-d,t-v-4));L({top:l,left:d,arrowLeft:u,openAbove:s})}},[O.anchorEl,O.refSectionTitle]);i.useEffect(function(){if(O.open){window.addEventListener("resize",K);var e=requestAnimationFrame(K);return function(){cancelAnimationFrame(e),window.removeEventListener("resize",K)}}},[O.open,K]),i.useEffect(function(){var n=V.current;if(n&&O.open){var i=function(n){console.log("Scroll event detected on:",n.target,"- closing CognitivePopup"),P(function(n){return e.__assign(e.__assign({},n),{open:!1,anchorEl:null,sectionAnchorEl:null})})};return n.addEventListener("scroll",i,{capture:!0}),window.addEventListener("scroll",i,{capture:!0}),function(){n.removeEventListener("scroll",i,{capture:!0}),window.removeEventListener("scroll",i,{capture:!0})}}},[O.open]);var G=i.useMemo(function(){var n,i,t,r,o,s,l,a,c,d,u,x;return{fields:null!==(n=null==E?void 0:E.fields)&&void 0!==n?n:b,thresholds:{high:null!==(t=null===(i=null==E?void 0:E.thresholds)||void 0===i?void 0:i.high)&&void 0!==t?t:y.thresholds.high,medium:null!==(o=null===(r=null==E?void 0:E.thresholds)||void 0===r?void 0:r.medium)&&void 0!==o?o:y.thresholds.medium,exact:null!==(l=null===(s=null==E?void 0:E.thresholds)||void 0===s?void 0:s.exact)&&void 0!==l?l:y.thresholds.exact},relationStyles:{noContent:e.__assign(e.__assign({},y.relationStyles.noContent),(null===(a=null==E?void 0:E.relationStyles)||void 0===a?void 0:a.noContent)||{}),high:e.__assign(e.__assign({},y.relationStyles.high),(null===(c=null==E?void 0:E.relationStyles)||void 0===c?void 0:c.high)||{}),exact:e.__assign(e.__assign({},y.relationStyles.exact),(null===(d=null==E?void 0:E.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e.__assign(e.__assign({},y.relationStyles.medium),(null===(u=null==E?void 0:E.relationStyles)||void 0===u?void 0:u.medium)||{}),low:e.__assign(e.__assign({},y.relationStyles.low),(null===(x=null==E?void 0:E.relationStyles)||void 0===x?void 0:x.low)||{})}}},[E]),Y=i.useMemo(function(){if(j&&Object.keys(j).length>0)try{var n=w(j);return e.__assign(e.__assign({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:B||[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:B||[],parseError:null}},[j,B]),J=Y.activeProposed,X=Y.activeVariants,$=Y.parseError;i.useEffect(function(){$&&R("Failed to load comparison: ".concat($))},[$]);var Z=i.useState(C||null),Q=Z[0],ee=Z[1],ne=i.useState(!1),ie=ne[0],te=ne[1],re=i.useState(null),oe=re[0],se=re[1],le=i.useState({}),ae=le[0],ce=le[1];i.useEffect(function(){if(C&&ee(C),se(null!=D?D:null),D){var e=setTimeout(function(){return se(null)},6e3);return function(){return clearTimeout(e)}}},[C,D]);var de=function(e){var n;null===(n=q.current)||void 0===n||n.scrollBy({left:"left"===e?-300:300,behavior:"smooth"})},ue=i.useMemo(function(){return e.__spreadArray([],X,!0).sort(function(e,n){return(n.similarity||0)-(e.similarity||0)})},[X]),xe=i.useMemo(function(){if(Q){var e=String(Q).trim();return X.find(function(n){return n.id&&String(n.id).trim()===e})||ue[0]}return ue[0]||null},[Q,X,ue]);i.useEffect(function(){Q&&q.current&&setTimeout(function(){var e=document.getElementById("variant-card-".concat(Q.trim())),n=q.current;if(e&&n){var i=e.offsetLeft-n.offsetLeft-n.clientWidth/2+e.clientWidth/2;n.scrollTo({left:i,behavior:"smooth"})}},150)},[Q,ue]);var ge=xe||{id:"",title:""},pe=g(J.title)||"Uploaded Contract",he=g(ge.title)||"Reference Template",fe=J.sections||[],ve=ge.sections||[],_e=fe.length>0||ve.length>0,me=null==xe?void 0:xe.analysis,be=g(null===(a=null===(s=null==me?void 0:me.rule_difference_comparison)||void 0===s?void 0:s.summary)||void 0===a?void 0:a.overall_summary),ye=!!be.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),Fe=null!==(c=null==xe?void 0:xe.similarity)&&void 0!==c?c:0,we=i.useRef({}),Be=function(e){return we.current[e]||(we.current[e]=d.default.createRef()),we.current[e]};i.useEffect(function(){!Q&&!C&&ue.length>0&&!ue[0].isLoading&&ee(ue[0].id)},[ue,Q,C]);var je=i.useRef(null),Ee=i.useRef(null),Se=i.useRef(null),Ce=i.useState([]),De=Ce[0],ke=Ce[1],Ae=i.useState(null),Re=Ae[0],Te=Ae[1],Ie=i.useState(!1),ze=Ie[0],We=Ie[1],Le=i.useState(!1),He=Le[0],Me=Le[1];i.useEffect(function(){var e=q.current;if(e){var n=function(){We(e.scrollLeft>0),Me(e.scrollLeft+e.clientWidth<e.scrollWidth-1)};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),function(){e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}}},[ue]);var Oe=i.useMemo(function(){return G.fields.filter(function(e){var n=e.key;return(!_e||"description"!==n)&&(F(J[n])||F(ge[n]))})},[J,ge,_e,G.fields]),Pe=i.useRef({}),qe=i.useRef({}),Ve=i.useRef({}),Ne=i.useRef({});Oe.forEach(function(e){var n=e.key;Pe.current[n]||(Pe.current[n]=d.default.createRef()),qe.current[n]||(qe.current[n]=d.default.createRef())});for(var Ue=0;Ue<Math.max(fe.length,ve.length);Ue+=1)Ve.current[Ue]||(Ve.current[Ue]=d.default.createRef()),Ne.current[Ue]||(Ne.current[Ue]=d.default.createRef());i.useEffect(function(){if(oe){var e=G.fields.find(function(e){return e.analysisKey===oe||e.key===oe});if(e){var n=Pe.current[e.key]||qe.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[oe,G.fields]);var Ke=function(e){var n,i,t,r,o,s,l,a,c,d=null===(n=null==me?void 0:me.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!d||!d[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var u=d[e],x=(null==u?void 0:u.relation)||(null===(t=null===(i=null==u?void 0:u.highlights)||void 0===i?void 0:i.ruleA_spans)||void 0===t?void 0:t.length)||(null===(o=null===(r=null==u?void 0:u.highlights)||void 0===r?void 0:r.ruleB_spans)||void 0===o?void 0:o.length)||(null==u?void 0:u.mappings)&&u.mappings.length>0;if(u.mappings){var g=u.mappings[0]||{};return{score:u.score,relation:g.relation||"",highlightsA:(null===(s=g.highlights)||void 0===s?void 0:s.ruleA_spans)||[],highlightsB:(null===(l=g.highlights)||void 0===l?void 0:l.ruleB_spans)||[],hasContent:!!x}}return{score:u.score,relation:u.relation||"",highlightsA:(null===(a=u.highlights)||void 0===a?void 0:a.ruleA_spans)||[],highlightsB:(null===(c=u.highlights)||void 0===c?void 0:c.ruleB_spans)||[],hasContent:!!x}},Ge=function(n){var i=ve[n];if("not_defined"===(null==i?void 0:i.relation))return e.__assign(e.__assign({},G.relationStyles.noContent),{label:"Not Defined"});var t,r=Ke("description");if(null!=(null==i?void 0:i.cognitiveRelevanceScore)){var o=(t=i.cognitiveRelevanceScore)>=90?{score:1,relation:"exact_match"}:t>=70?{score:.8,relation:"high_match"}:t>=40?{score:.5,relation:"partial_match"}:{score:0,relation:"no_deviation"};return h(o.score,o.relation,!0,G)}var s=null!=(null==i?void 0:i.relation)&&""!==i.relation?i.relation:r.relation,l="number"==typeof(null==i?void 0:i.score)?i.score:r.score;return h(l,s,!0,G)},Ye=function(){var e,n,i;if(!U.current){U.current=!0;try{if(!je.current)return;var t=je.current.getBoundingClientRect(),r=[];Oe.forEach(function(e){var n=e.key,i=e.analysisKey,o=Pe.current[n],s=qe.current[n];if((null==o?void 0:o.current)&&(null==s?void 0:s.current)){o.current.style.height="auto",s.current.style.height="auto",o.current.style.minHeight="0px",s.current.style.minHeight="0px";var l=o.current.getBoundingClientRect().height,a=s.current.getBoundingClientRect().height,c=Math.max(l,a);o.current.style.minHeight="".concat(c,"px"),s.current.style.minHeight="".concat(c,"px");var d=o.current.getBoundingClientRect(),u=s.current.getBoundingClientRect(),x=Ke(i),g=h(x.score,x.relation,x.hasContent,G);if(!g)return;var p=d.top+d.height/2-t.top;r.push({id:"field-".concat(n),x1:d.right-t.left,y1:p,x2:u.left-t.left,y2:p,style:g})}});for(var o=Math.min(fe.length,ve.length),s=0;s<o;s+=1){var l=Ve.current[s],a=Ne.current[s];if((null==l?void 0:l.current)&&(null==a?void 0:a.current)){l.current.style.height="auto",a.current.style.height="auto",l.current.style.minHeight="0px",a.current.style.minHeight="0px";var c=Math.max(l.current.getBoundingClientRect().height,a.current.getBoundingClientRect().height);l.current.style.minHeight="".concat(c,"px"),a.current.style.minHeight="".concat(c,"px");var d=l.current.querySelector(".MuiAccordionSummary-root"),u=a.current.querySelector(".MuiAccordionSummary-root");if(d&&u){var x=d.getBoundingClientRect(),g=u.getBoundingClientRect(),p=(x.top+x.height/2-t.top+g.top+g.height/2-t.top)/2,f=(null===(e=ve[s])||void 0===e?void 0:e.id)||"sec-".concat(s),v=Ge(s);v&&r.push({id:f,x1:x.right-t.left,y1:p,x2:g.left-t.left,y2:p,style:v,sectionIdx:s,hasCognitive:!(!(null===(n=fe[s])||void 0===n?void 0:n.cognitiveData)&&!(null===(i=ve[s])||void 0===i?void 0:i.cognitiveData))})}}}if(ke(r),Ee.current&&Se.current){var _=Ee.current.getBoundingClientRect(),m=Se.current.getBoundingClientRect(),b=(_.top+_.height/2-t.top+m.top+m.height/2-t.top)/2;Te({x1:_.right-t.left,x2:m.left-t.left,y:b})}else Te(null)}catch(e){console.error("Line render safe fail: ",e)}finally{U.current=!1}}};i.useEffect(function(){var e=setTimeout(Ye,250);window.addEventListener("resize",Ye);var n=null;return V.current&&(n=new ResizeObserver(function(){return window.requestAnimationFrame(Ye)})).observe(V.current),function(){clearTimeout(e),window.removeEventListener("resize",Ye),null==n||n.disconnect()}},[J,ge,me,ie,Oe,ae,fe,ve,G]);var Je={fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,wordBreak:"break-word",overflowWrap:"break-word",overflow:"hidden","& p":{mt:0,mb:1.5},"& p:last-child":{mb:0},"& ul, & ol":{mt:0,mb:1.5,pl:2.5},"& li":{mb:.5},"& strong":{fontWeight:600},"& code":{whiteSpace:"pre-wrap",wordBreak:"break-word"}},Xe=function(i,o,s,l){return n.jsx(t.Box,e.__assign({ref:l,sx:{mb:1,minHeight:0,display:"flex",flexDirection:"column"}},{children:n.jsxs(t.Accordion,e.__assign({disableGutters:!0,expanded:!!ae[o],onChange:function(){return n=o,void ce(function(i){var t;return e.__assign(e.__assign({},i),((t={})[n]=!i[n],t))});var n},sx:{boxShadow:"none",border:"1px solid #E2E8F0",bgcolor:"#FFFFFF",borderRadius:"6px",flex:1,display:"flex",flexDirection:"column","&:before":{display:"none"}}},{children:[n.jsx(t.AccordionSummary,e.__assign({expandIcon:n.jsx(r.ChevronDown,{size:16}),sx:{minHeight:"36px",flexShrink:0,"& .MuiAccordionSummary-content":{my:.5,display:"flex",alignItems:"center",overflow:"hidden"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"12px",color:"#19213D",fontWeight:500,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},{children:p(i.title||"Section ".concat(o+1))}))})),n.jsxs(t.AccordionDetails,e.__assign({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column"}},{children:[n.jsx(t.Typography,e.__assign({component:"div",sx:Je},{children:n.jsx(x.default,{children:g(i.content).replace(/\\n/g,"\n")})})),(i.subsections||[]).map(function(i,r){return n.jsx(t.Box,e.__assign({sx:{mt:1,pt:1,borderTop:"1px solid #EEF2F7"}},{children:n.jsx(t.Typography,e.__assign({component:"div",sx:Je},{children:n.jsx(x.default,{children:g(i).replace(/\\n/g,"\n")})}))}),"".concat(s,"-sub-").concat(o,"-").concat(r))})]}))]}))}),"".concat(s,"-sec-").concat(o))};return n.jsxs(t.Box,e.__assign({ref:N,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[O.open&&n.jsx(_,{open:O.open,popupRef:H,position:W,onClose:function(){return P(function(n){return e.__assign(e.__assign({},n),{open:!1})})},sectionTitle:O.sectionTitle,referenceSectionTitle:O.refSectionTitle,cognitiveData:O.cognitiveData,anchorEl:O.anchorEl,sectionAnchorEl:O.sectionAnchorEl,scrollContainerEl:V.current,badgeStyle:O.badgeStyle}),n.jsx(t.Snackbar,e.__assign({open:!!A,autoHideDuration:8e3,onClose:function(){return R(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(t.Alert,e.__assign({onClose:function(){return R(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:A}))})),n.jsx(t.Box,e.__assign({sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:"#FFFFFF",border:"1.5px solid #EEF0F4"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:450,color:"#0F172A"}},{children:"Learning Comparison"}))}))})),ue.length>1&&n.jsxs(t.Box,e.__assign({sx:{px:3,pb:.25},ref:I},{children:[n.jsxs(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",color:"#475569"}},{children:"Choose the Learning you want to compare with the rule you are creating."})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",gap:.5,flexShrink:0,ml:1}},{children:[n.jsx(t.IconButton,e.__assign({onClick:function(){return de("left")},size:"small",disabled:!ze},{children:n.jsx(r.ArrowLeft,{size:18})})),n.jsx(t.IconButton,e.__assign({onClick:function(){return de("right")},size:"small",disabled:!He},{children:n.jsx(r.ArrowRight,{size:18})}))]}))]})),n.jsx(t.Box,e.__assign({ref:q,sx:{display:"flex",gap:1,overflowX:"auto",pb:.05,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"transparent",borderRadius:"10px"}}},{children:ue.map(function(e){return n.jsx(m,{data:e,isSelected:(null==xe?void 0:xe.id)===e.id,isCognitiveOpen:ie,onToggleCognitive:function(){return te(function(e){return!e})},onClick:function(){return ee((n=e).id),S(n),void te(!1);var n}},e.id)})}))]})),n.jsx(t.Box,e.__assign({ref:V,sx:{flex:1,overflowY:"auto",minHeight:0,pt:1.5,pb:8,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",borderTop:be&&ye&&ie?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"}},{children:n.jsxs(t.Box,e.__assign({ref:je,sx:{display:"grid",gridTemplateColumns:"1fr auto 1fr",gap:"60px",maxWidth:"1200px",width:"100%",position:"relative"}},{children:[n.jsxs("svg",e.__assign({style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10}},{children:[Re&&n.jsxs("g",{children:[n.jsx("line",{x1:Re.x1,y1:Re.y,x2:Math.max(Re.x1,(Re.x1+Re.x2)/2-70),y2:Re.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),n.jsx("line",{x1:Math.min(Re.x2,(Re.x1+Re.x2)/2+70),y1:Re.y,x2:Re.x2,y2:Re.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),De.map(function(i,o){var s=(i.x1+i.x2)/2;return i.id||"line-".concat(o),"Not Defined"===i.style.label?null:n.jsxs("g",{children:[n.jsx("line",{x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,stroke:i.style.badgeBorder,strokeWidth:"1.5"}),n.jsx("foreignObject",e.__assign({x:s-75,y:i.y1-14,width:"150",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:n.jsxs(t.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:i.style.badgeBg,color:i.style.badgeText,border:"1px solid ".concat(i.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:500,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"},onClick:function(e){e.stopPropagation(),function(e,n,i,t,r){var o,s;e.stopPropagation();var l=g(n.id)||g(i.id)||"",a=(l?T[l]:null)||n.cognitiveData||i.cognitiveData||null,c=null!==(s=null===(o=we.current[t])||void 0===o?void 0:o.current)&&void 0!==s?s:null;P({open:!0,sectionTitle:n.title||"Section",refSectionTitle:i.title||"Reference Section",cognitiveData:a,anchorEl:e.currentTarget,sectionAnchorEl:c,badgeStyle:r||null,sectionIdx:t})}(e,fe[i.sectionIdx]||{title:"",content:""},ve[i.sectionIdx]||{title:"",content:""},i.sectionIdx,i.style)}},{children:[i.style.label,i.hasCognitive&&void 0!==i.sectionIdx&&n.jsx(t.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"4px",px:"4px",ml:"2px",color:i.style.badgeText,transition:"background 0.15s","&:hover":{backgroundColor:"rgba(0,0,0,0.05)"}}},{children:n.jsx("div",e.__assign({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:n.jsx(l.ButtonCognitiveIcon,{})}))})),O.open&&O.sectionIdx===i.sectionIdx?n.jsx(r.ChevronUp,{size:12,color:i.style.badgeText}):n.jsx(r.ChevronDown,{size:12,color:i.style.badgeText})]}))}))}))]},o)})]})),n.jsxs(t.Box,e.__assign({sx:{border:"1px dashed #B0B0B0",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)",minWidth:0}},{children:[n.jsx(t.Box,e.__assign({ref:Ee,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px dashed #B0B0B0",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"24px",alignItems:"center"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D"}},{children:pe}))})),n.jsxs(t.Box,e.__assign({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[Oe.map(function(e){var i=e.key,t=e.label,r=e.analysisKey,o=Ke(r),s=J[i],l=ge[i];if(!F(s)&&!F(l))return null;var a=h(o.score,o.relation,o.hasContent,G);return a?n.jsx(f,{ref:Pe.current[i],label:t,content:s,highlights:o.highlightsA,styleVariant:a,isHighlighted:oe===r||oe===i},"left-".concat(i)):null}),_e&&fe.map(function(e,n){return{section:e,idx:n}}).filter(function(e){var n=e.section;return F(n.title)||F(n.content)||(n.subsections||[]).some(F)}).map(function(i){var r=i.section,o=i.idx;return n.jsx(t.Box,e.__assign({ref:Be(o)},{children:Xe(r,o,"left",Ve.current[o]||d.default.createRef())}),"left-row-".concat(o))})]}))]})),n.jsx(t.Box,e.__assign({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"6px",gap:0}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(t.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(t.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(l.ButtonCognitiveIcon,{})})),Fe,"% Similarity",n.jsx(r.ChevronDown,{size:11})]}))}))})),n.jsxs(t.Box,e.__assign({sx:{border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0}},{children:[n.jsx(t.Box,e.__assign({ref:Se,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"24px",display:"flex",alignItems:"center"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",display:"flex",alignItems:"center",gap:1}},{children:he}))})),n.jsxs(t.Box,e.__assign({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[Oe.map(function(e){var i=e.key,t=e.label,r=e.analysisKey,o=Ke(r),s=J[i],l=ge[i];if(!F(s)&&!F(l))return null;var a=h(o.score,o.relation,o.hasContent,G);return a?n.jsx(f,{ref:qe.current[i],label:t,content:l,highlights:o.highlightsB,styleVariant:a,isHighlighted:oe===r||oe===i},"right-".concat(i)):null}),_e&&ve.map(function(e,n){return{section:e,idx:n}}).filter(function(e){var n=e.section;return F(n.title)||F(n.content)||(n.subsections||[]).some(F)}).map(function(e){var n=e.section,i=e.idx;return Xe(n,i,"right",Ne.current[i]||d.default.createRef())})]}))]}))]}))}))}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),i=require("react"),t=require("@mui/material"),o=require("lucide-react"),r=require("react-dom"),s=require("../../assests/svg/SparkleIcon.js"),l=require("../../assests/svg/ButtonCognitiveIcon.js"),a=require("react-markdown");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(i),u=c(r),x=c(a),g=function(e){return null==e?"":"string"==typeof e?e:Array.isArray(e)?e.map(g).join("\n\n"):"object"==typeof e?JSON.stringify(e):String(e)},p={fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,wordBreak:"break-word",overflowWrap:"break-word",overflow:"hidden","& p":{mt:0,mb:1.5},"& p:last-child":{mb:0},"& ul, & ol":{mt:0,mb:1.5,pl:2.5},"& li":{mb:.5},"& strong":{fontWeight:600},"& code":{whiteSpace:"pre-wrap",wordBreak:"break-word"}},h=function(e){return e?g(e).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,i){return e.startsWith("**")&&e.endsWith("**")?n.jsx("strong",{children:e.slice(2,-2)},i):n.jsx(d.default.Fragment,{children:e},i)}):null},f=function(n,i,t,o){var r=100*(n||0),s=o.thresholds,l=o.relationStyles;if(!t)return null;var a=function(e){return e&&"string"==typeof e?e.split("_").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}).join(" "):"Unknown"}(i),c=(i||"").toLowerCase();return c.includes("no_deviation")?e.__assign(e.__assign({},l.low),{label:a}):c.includes("deviation")||c.includes("high_risk")||c.includes("critical")?e.__assign(e.__assign({},l.high),{label:a}):r>=s.exact?e.__assign(e.__assign({},l.exact),{label:a}):r>=s.high?e.__assign(e.__assign({},l.high),{label:a}):r>=s.medium?e.__assign(e.__assign({},l.medium),{label:a}):e.__assign(e.__assign({},l.low),{label:a})},v=function(i,o,r){if(!i)return null;if(!o||0===o.length)return h(i);var s=o.filter(function(e){return e&&"string"==typeof e&&e.length>0}).map(function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")});if(0===s.length)return h(i);var l=new RegExp("(".concat(s.join("|"),")"),"gi");return i.split(l).map(function(i,s){return o.some(function(e){return e&&"string"==typeof e&&e.toLowerCase()===i.toLowerCase()})?n.jsx(t.Box,e.__assign({component:"span",sx:{bgcolor:r.highlightBg,borderRadius:"2px",px:"2px"}},{children:h(i)}),s):n.jsx(d.default.Fragment,{children:h(i)},s)})},_=d.default.memo(d.default.forwardRef(function(i,o){var r=i.label,s=i.content,l=i.highlights,a=void 0===l?[]:l,c=i.styleVariant,d=i.isHighlighted,u=void 0!==d&&d,x=Array.isArray(s)?s.map(g).join("\n"):g(s),p=function(e){return"#9F1239"===e.badgeText?{borderColor:"#E11D48",shadow:"rgba(225, 29, 72, 0.25)"}:"#B91C1C"===e.badgeText?{borderColor:"#EF4444",shadow:"rgba(239, 68, 68, 0.25)"}:"#1D4ED8"===e.badgeText?{borderColor:"#3B82F6",shadow:"rgba(59, 130, 246, 0.25)"}:"#A16207"===e.badgeText?{borderColor:"#F59E0B",shadow:"rgba(245, 158, 11, 0.25)"}:{borderColor:"#6366F1",shadow:"rgba(99, 102, 241, 0.25)"}}(c);return n.jsxs(t.Box,e.__assign({sx:{mb:1.5}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"12px",color:"#19213D",mb:.5,fontWeight:500}},{children:r})),n.jsx(t.Box,e.__assign({ref:o,sx:{p:"4px 12px",borderRadius:"6px",border:u?"1.5px solid ".concat(p.borderColor):"1px solid ".concat(c.border),boxShadow:u?"0px 0px 0px 2px ".concat(p.shadow):"none",bgcolor:c.bg,fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,minHeight:"24px",display:"flex",alignItems:"center",whiteSpace:"pre-line",wordBreak:"break-word"}},{children:n.jsx(t.Box,{children:v(x,a,c)})}))]}))})),m=12,b=10,y=function(r){var l,a,c,d,g,h=r.open,f=r.onClose,v=r.sectionTitle,_=r.referenceSectionTitle,m=r.cognitiveData,y=r.relevanceScore,F=r.anchorEl,w=r.badgeStyle,B=r.popupRef,j=r.position,E=i.useState("association"),C=E[0],S=E[1],D=i.useMemo(function(){if(!w)return{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"};var e=w.badgeText;return"#9F1239"===e||"#B42318"===e?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===e?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===e?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"}},[w]);if(i.useEffect(function(){if(h){var e=function(e){var n;(null===(n=B.current)||void 0===n?void 0:n.contains(e.target))||(null==F?void 0:F.contains(e.target))||f()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[h,f,F,B]),!h||!m)return null;var k=null!==(a=null!==(l=m.relevance_score)&&void 0!==l?l:y)&&void 0!==a?a:0,R=m.decisioning,A=Array.isArray(R)?R:"string"==typeof R&&R.trim()?[R]:[],T=m.gap,I=Array.isArray(T)?T:"string"==typeof T&&T.trim()?[T]:[],z=null!==(c=null==j?void 0:j.arrowLeft)&&void 0!==c?c:60,W=n.jsxs(t.Box,e.__assign({ref:B,sx:{position:"fixed",top:null!==(d=null==j?void 0:j.top)&&void 0!==d?d:-9999,left:null!==(g=null==j?void 0:j.left)&&void 0!==g?g:-9999,zIndex:9999,width:"min(".concat(680,"px, calc(100vw - ").concat(24,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat(D.border),boxShadow:"0px 8px 32px ".concat(D.shadow,", 0px 0px 0px 3px ").concat(D.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:(null==j?void 0:j.maxHeight)?"min(60vh, ".concat(j.maxHeight,"px)"):"60vh",visibility:j?"visible":"hidden"}},{children:[j&&(j.openAbove?n.jsxs(n.Fragment,{children:[n.jsx(t.Box,{sx:{position:"absolute",bottom:-11,left:z-b,width:0,height:0,borderLeft:"".concat(b,"px solid transparent"),borderRight:"".concat(b,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat(D.border),zIndex:1}}),n.jsx(t.Box,{sx:{position:"absolute",bottom:-9,left:z-b+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(b,"px solid #FFFFFF"),zIndex:2}})]}):n.jsxs(n.Fragment,{children:[n.jsx(t.Box,{sx:{position:"absolute",top:-11,left:z-b,width:0,height:0,borderLeft:"".concat(b,"px solid transparent"),borderRight:"".concat(b,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat(D.border),zIndex:1}}),n.jsx(t.Box,{sx:{position:"absolute",top:-9,left:z-b+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(b,"px solid #FFFFFF"),zIndex:2}})]})),n.jsxs(t.Box,e.__assign({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[n.jsxs(t.Box,e.__assign({sx:{flex:1,minWidth:0}},{children:[n.jsxs(t.Typography,e.__assign({sx:{fontSize:"18px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden"}},{children:[n.jsx(t.Box,e.__assign({component:"span",title:v,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:v})),n.jsx(t.Box,e.__assign({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),n.jsx(t.Box,e.__assign({component:"span",title:_||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:_||"Reference Section"}))]})),n.jsx(t.Box,e.__assign({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:"deviation"===C?"Why this is a deviation?":"Why these sections are paired?"}))}))]})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[n.jsxs(t.Box,e.__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:[n.jsx(s.default,{}),"Decision Strength ",k,"%"]})),n.jsx(t.IconButton,e.__assign({onClick:f,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:n.jsx(o.X,{size:22})}))]}))]})),n.jsx(t.Box,e.__assign({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:["deviation","association"].map(function(i){var o=C===i,r="deviation"===i?"Deviation Analysis":"Association Logic";return n.jsx(t.Box,e.__assign({onClick:function(){return S(i)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:o?600:400,color:o?"#5928ED":"#667085",backgroundColor:o?"rgba(89,40,237,0.08)":"transparent",borderBottom:o?"2px solid #5928ED":"2px solid transparent",transition:"all 0.15s",userSelect:"none",overflowY:"auto"}},{children:r}),i)})})),n.jsx(t.Box,e.__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(D.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:D.border},scrollbarWidth:"thin",scrollbarColor:"".concat(D.border,"55 transparent")}},{children:"deviation"===C?n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD",p:2,display:"flex",flexDirection:"column",gap:1}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054"}},{children:"Deviation Analysis"})),n.jsx(t.Typography,e.__assign({sx:{fontSize:"14px",color:"#667085",lineHeight:1.6}},{children:"Deviation analysis content will appear here. This tab shows structural and semantic deviations identified between the two sections being compared."}))]})):n.jsxs(n.Fragment,{children:[A.length>0&&n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[n.jsx(t.Box,e.__assign({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Decision Making Factors"}))})),n.jsx(t.Box,e.__assign({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column"}},{children:n.jsx(t.Typography,e.__assign({component:"div",sx:e.__assign({},p)},{children:n.jsx(x.default,{children:A.join("\n\n")})}))}))}))]})),I.length>0&&n.jsxs(t.Box,e.__assign({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[n.jsx(t.Box,e.__assign({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Gaps in Decision"}))})),n.jsx(t.Box,e.__assign({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column"}},{children:n.jsx(t.Typography,e.__assign({component:"div",sx:e.__assign({},p)},{children:n.jsx(x.default,{children:I.join("\n\n")})}))}))}))]})),0===A.length&&0===I.length&&n.jsx(t.Box,e.__assign({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]})}))]}));return u.default.createPortal(W,document.body)},F=d.default.memo(function(i){var r=i.data,s=i.isSelected,a=i.isCognitiveOpen,c=i.onToggleCognitive,d=i.onClick,u=g(r.summaryText||r.description),x=u.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),p=x?u.replace(x[0],"").trim():u,h=!!x;return n.jsxs(t.Box,e.__assign({id:"variant-card-".concat(r.id),onClick:d,sx:{minWidth:"280px",maxWidth:"280px",p:2,m:.5,bgcolor:s?"#EFF6FF99":"#FFFFFF",borderRadius:"8px",cursor:"pointer",transition:"all 0.2s",display:"flex",flexDirection:"column",gap:1,flexShrink:0,opacity:r.isLoading?.7:1,border:s?"1.4px solid #2563EB":void 0,boxShadow:s?"none":"0px 2px 4px 0px #19213D14","&:hover":{borderColor:s?"#2563EB":"#CBD5E1",boxShadow:s?"none":"0px 4px 8px 0px #19213D1F"}}},{children:[n.jsx(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1.5}},{children:r.isLoading?n.jsx(t.Skeleton,{variant:"rounded",width:80,height:20}):n.jsxs(t.Box,e.__assign({sx:{bgcolor:"#FEF2F2",color:"#B91C1C",fontSize:"11px",fontWeight:600,px:1,py:.5,borderRadius:"100px",border:"1px solid #FFE1E1"}},{children:[void 0!==r.similarity?r.similarity:0,"% Similarity"]}))})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:1}},{children:[n.jsx(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontWeight:500,fontSize:"14px",color:"#19213D",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"}},{children:g(r.title)}))})),r.isLoading?n.jsxs(t.Box,{children:[n.jsx(t.Skeleton,{width:"90%"}),n.jsx(t.Skeleton,{width:"60%"})]}):n.jsxs(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontWeight:400,fontSize:"13px",color:"#666F8D",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"}},{children:p})),h&&n.jsxs(t.Box,e.__assign({onClick:function(e){e.stopPropagation(),s||d(),c()},sx:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",cursor:"pointer",marginLeft:"-4px","&:hover":{backgroundColor:"#F1F5F9"}}},{children:[n.jsx("div",e.__assign({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:n.jsx(l.ButtonCognitiveIcon,{})})),n.jsx(o.ChevronDown,{size:12,style:{transform:s&&a?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}))]}))]}))]}))}),w=[{key:"title",label:"Title",analysisKey:"title"},{key:"description",label:"Description",analysisKey:"description"}],B={fields:w,thresholds:{exact:90,high:70,medium:40},relationStyles:{noContent:{bg:"#FFFFFF",border:"#E2E8F0",badgeBg:"#F8FAFC",badgeBorder:"#F1F5F9",badgeText:"#64748B",highlightBg:"transparent"},exact:{bg:"#FFF1F2",border:"#FECDD3",badgeBg:"#FFE4E6",badgeBorder:"#FEE2E2",badgeText:"#9F1239",highlightBg:"#FECDD3"},high:{bg:"#FFF5F5",border:"#FECACA",badgeBg:"#FEECEC",badgeBorder:"#F8C2C2",badgeText:"#B42318",highlightBg:"#FDD5D5"},medium:{bg:"#FFFCF6",border:"#FFDD80",badgeBg:"#FEF9C3",badgeBorder:"#FEF08A",badgeText:"#A16207",highlightBg:"#FDDEB3"},low:{bg:"#F5F9FF",border:"#CFE0FF",badgeBg:"#EEF4FF",badgeBorder:"#BFD3FF",badgeText:"#1D4ED8",highlightBg:"#DCEAFF"}}},j=function(e){return null!=e&&("string"==typeof e?e.trim().length>0:!Array.isArray(e)||e.length>0&&e.some(function(e){return j(e)}))},E=function(e,n,i){var t,o=i[n],r=null===(t=null==e?void 0:e.comparison_inputs)||void 0===t?void 0:t[o];return{title:g((null==r?void 0:r.title)||""),content:g((null==r?void 0:r.content)||"")}},C=function(n){var i,t,o,r,s=[],l=[],a=n.base_root_id,c=n.input_index_map||{0:"left",1:"right"},d=n[a];if(!d||!1===d.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var u=function(i){var t=n[i];if(t&&!1!==t.display_node){var o=function(e){if(!e.mapping_rationale)return{score:void 0,relation:"not_defined"};var n=e.mapping_rationale,i=!n.decision_strength,t=parseInt(n.decision_strength||"0");return{cognitiveData:{decisioning:n.decisioning_factors||[],gap:n.gaps_in_decision||[],relevance_score:t},score:i?100:t/100,relation:t>=70?"no_deviation":"deviation"}}(t),r=E(t,"0",c),a=E(t,"1",c),d=r.title.trim()||r.content.trim(),x=a.title.trim()||a.content.trim();s.push(e.__assign({id:i,title:d?r.title:"",content:d?r.content:"",subsections:[]},d?o:{score:void 0,relation:"not_defined"})),l.push(e.__assign({id:i,title:x?a.title:"",content:x?a.content:"",subsections:[]},x?o:{score:void 0,relation:"not_defined"})),t.next&&Object.values(t.next).forEach(u)}};return d.next&&Object.values(d.next).forEach(u),{activeProposed:{title:(null===(t=null===(i=d.comparison_inputs)||void 0===i?void 0:i[c[0]])||void 0===t?void 0:t.title)||"Uploaded Contract",description:d.decision_scope_description||"",sections:s},activeVariants:[{id:"tree-variant-1",title:(null===(r=null===(o=d.comparison_inputs)||void 0===o?void 0:o[c[1]])||void 0===r?void 0:r.title)||"Reference Template",similarity:0,sections:l,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:d.decision_scope_description||""},fields:{}}}}]}},S={id:"",title:""};exports.DEFAULT_COMPARISON_CONFIG=B,exports.DEFAULT_FIELD_CONFIG=w,exports.default=function(r){var s,a,c,u=r.variants,v=void 0===u?[]:u,E=r.treeData,D=r.comparisonConfig,k=r.onSelectVariant,R=r.targetVariantId,A=r.highlightedField,T=i.useState(null),I=T[0],z=T[1],W=i.useMemo(function(){return(null==E?void 0:E.cognitive_decisioning)||{}},[E]),L=i.useRef(null),H=i.useState(null),M=H[0],O=H[1],q=i.useRef(null),P=i.useState({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null}),V=P[0],N=P[1],U=i.useRef(null),K=i.useRef(null),G=i.useRef(null),Y=i.useRef(!1),J=i.useRef(null);i.useEffect(function(){J.current=null},[V.sectionIdx,V.open]);var X=i.useCallback(function(){var e;if(V.anchorEl&&V.refSectionTitle){var n=V.anchorEl.getBoundingClientRect(),i=(null===(e=null==q?void 0:q.current)||void 0===e?void 0:e.offsetHeight)||0,t=Math.min(680,window.innerWidth-24),o=window.innerHeight-n.bottom-12-m,r=n.top-12-m,s=o<i&&r>o;null!==J.current?!0===J.current&&(s=r>=i||r>=o):s=!(o>=i||o>=r),J.current=s;var l=s?r:o,a=Math.min(i||9999,l),c=s?n.top-12-a:n.bottom+12,d=n.left+n.width/2,u=d-t/2,x=Math.max(m,Math.min(u,window.innerWidth-t-m)),g=Math.max(14,Math.min(d-x,t-b-4));O({top:c,left:x,arrowLeft:g,openAbove:s,maxHeight:l})}},[V.anchorEl,V.refSectionTitle]);i.useEffect(function(){if(V.open){window.addEventListener("resize",X);var e=requestAnimationFrame(X),n=null;return q.current&&(n=new ResizeObserver(function(){e=requestAnimationFrame(X)})).observe(q.current),function(){cancelAnimationFrame(e),window.removeEventListener("resize",X),n&&n.disconnect()}}},[V.open,X]),i.useEffect(function(){var n=K.current;if(n&&V.open){var i=function(n){q.current&&q.current.contains(n.target)||(console.log("Scroll event detected on:",n.target,"- closing CognitivePopup"),O(null),N(function(n){return e.__assign(e.__assign({},n),{open:!1,anchorEl:null,sectionAnchorEl:null})}))};return n.addEventListener("scroll",i,{capture:!0}),window.addEventListener("scroll",i,{capture:!0}),function(){n.removeEventListener("scroll",i,{capture:!0}),window.removeEventListener("scroll",i,{capture:!0})}}},[V.open]);var $=i.useMemo(function(){var n,i,t,o,r,s,l,a,c,d,u,x;return{fields:null!==(n=null==D?void 0:D.fields)&&void 0!==n?n:w,thresholds:{high:null!==(t=null===(i=null==D?void 0:D.thresholds)||void 0===i?void 0:i.high)&&void 0!==t?t:B.thresholds.high,medium:null!==(r=null===(o=null==D?void 0:D.thresholds)||void 0===o?void 0:o.medium)&&void 0!==r?r:B.thresholds.medium,exact:null!==(l=null===(s=null==D?void 0:D.thresholds)||void 0===s?void 0:s.exact)&&void 0!==l?l:B.thresholds.exact},relationStyles:{noContent:e.__assign(e.__assign({},B.relationStyles.noContent),(null===(a=null==D?void 0:D.relationStyles)||void 0===a?void 0:a.noContent)||{}),high:e.__assign(e.__assign({},B.relationStyles.high),(null===(c=null==D?void 0:D.relationStyles)||void 0===c?void 0:c.high)||{}),exact:e.__assign(e.__assign({},B.relationStyles.exact),(null===(d=null==D?void 0:D.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e.__assign(e.__assign({},B.relationStyles.medium),(null===(u=null==D?void 0:D.relationStyles)||void 0===u?void 0:u.medium)||{}),low:e.__assign(e.__assign({},B.relationStyles.low),(null===(x=null==D?void 0:D.relationStyles)||void 0===x?void 0:x.low)||{})}}},[D]),Q=i.useMemo(function(){if(E&&Object.keys(E).length>0)try{var n=C(E);return e.__assign(e.__assign({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:v||[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:v||[],parseError:null}},[E,v]),Z=Q.activeProposed,ee=Q.activeVariants,ne=Q.parseError;i.useEffect(function(){ne&&z("Failed to load comparison: ".concat(ne))},[ne]);var ie=i.useState(R||null),te=ie[0],oe=ie[1],re=i.useState(!1),se=re[0],le=re[1],ae=i.useState(null),ce=ae[0],de=ae[1],ue=i.useState({}),xe=ue[0],ge=ue[1];i.useEffect(function(){if(R&&oe(R),de(null!=A?A:null),A){var e=setTimeout(function(){return de(null)},6e3);return function(){return clearTimeout(e)}}},[R,A]);var pe=function(e){var n;null===(n=U.current)||void 0===n||n.scrollBy({left:"left"===e?-300:300,behavior:"smooth"})},he=i.useMemo(function(){return e.__spreadArray([],ee,!0).sort(function(e,n){return(n.similarity||0)-(e.similarity||0)})},[ee]),fe=i.useMemo(function(){if(te){var e=String(te).trim();return ee.find(function(n){return n.id&&String(n.id).trim()===e})||he[0]}return he[0]||null},[te,ee,he]);i.useEffect(function(){te&&U.current&&setTimeout(function(){var e=document.getElementById("variant-card-".concat(te.trim())),n=U.current;if(e&&n){var i=e.offsetLeft-n.offsetLeft-n.clientWidth/2+e.clientWidth/2;n.scrollTo({left:i,behavior:"smooth"})}},150)},[te,he]);var ve=fe||S,_e=g(Z.title)||"Uploaded Contract",me=g(ve.title)||"Reference Template",be=i.useMemo(function(){return Z.sections||[]},[Z.sections]),ye=i.useMemo(function(){return ve.sections||[]},[ve.sections]),Fe=be.length>0||ye.length>0,we=null==fe?void 0:fe.analysis,Be=g(null===(a=null===(s=null==we?void 0:we.rule_difference_comparison)||void 0===s?void 0:s.summary)||void 0===a?void 0:a.overall_summary),je=!!Be.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),Ee=null!==(c=null==fe?void 0:fe.similarity)&&void 0!==c?c:0,Ce=i.useRef({}),Se=function(e){return Ce.current[e]||(Ce.current[e]=d.default.createRef()),Ce.current[e]};i.useEffect(function(){!te&&!R&&he.length>0&&!he[0].isLoading&&oe(he[0].id)},[he,te,R]);var De=i.useRef(null),ke=i.useRef(null),Re=i.useRef(null),Ae=i.useState([]),Te=Ae[0],Ie=Ae[1],ze=i.useState(null),We=ze[0],Le=ze[1],He=i.useState(!1),Me=He[0],Oe=He[1],qe=i.useState(!1),Pe=qe[0],Ve=qe[1];i.useEffect(function(){var e=U.current;if(e){var n=function(){Oe(e.scrollLeft>0),Ve(e.scrollLeft+e.clientWidth<e.scrollWidth-1)};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),function(){e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}}},[he]);var Ne=i.useMemo(function(){return $.fields.filter(function(e){var n=e.key;return(!Fe||"description"!==n)&&(j(Z[n])||j(ve[n]))})},[Z,ve,Fe,$.fields]),Ue=i.useRef({}),Ke=i.useRef({}),Ge=i.useRef({}),Ye=i.useRef({});Ne.forEach(function(e){var n=e.key;Ue.current[n]||(Ue.current[n]=d.default.createRef()),Ke.current[n]||(Ke.current[n]=d.default.createRef())});for(var Je=0;Je<Math.max(be.length,ye.length);Je+=1)Ge.current[Je]||(Ge.current[Je]=d.default.createRef()),Ye.current[Je]||(Ye.current[Je]=d.default.createRef());i.useEffect(function(){if(ce){var e=$.fields.find(function(e){return e.analysisKey===ce||e.key===ce});if(e){var n=Ue.current[e.key]||Ke.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[ce,$.fields]);var Xe=i.useCallback(function(e){var n,i,t,o,r,s,l,a,c,d=null===(n=null==we?void 0:we.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!d||!d[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var u=d[e],x=(null==u?void 0:u.relation)||(null===(t=null===(i=null==u?void 0:u.highlights)||void 0===i?void 0:i.ruleA_spans)||void 0===t?void 0:t.length)||(null===(r=null===(o=null==u?void 0:u.highlights)||void 0===o?void 0:o.ruleB_spans)||void 0===r?void 0:r.length)||(null==u?void 0:u.mappings)&&u.mappings.length>0;if(u.mappings){var g=u.mappings[0]||{};return{score:u.score,relation:g.relation||"",highlightsA:(null===(s=g.highlights)||void 0===s?void 0:s.ruleA_spans)||[],highlightsB:(null===(l=g.highlights)||void 0===l?void 0:l.ruleB_spans)||[],hasContent:!!x}}return{score:u.score,relation:u.relation||"",highlightsA:(null===(a=u.highlights)||void 0===a?void 0:a.ruleA_spans)||[],highlightsB:(null===(c=u.highlights)||void 0===c?void 0:c.ruleB_spans)||[],hasContent:!!x}},[we]),$e=i.useCallback(function(n){var i,t,o=be[n],r=ye[n],s=(null==o?void 0:o.relation)&&"not_defined"!==o.relation,l=(null==r?void 0:r.relation)&&"not_defined"!==r.relation,a=!(!(null==o?void 0:o.cognitiveData)&&!(null==r?void 0:r.cognitiveData));if(!s&&!l&&!a)return e.__assign(e.__assign({},$.relationStyles.noContent),{label:"Not Defined"});var c,d=Xe("description"),u=null!==(i=null==o?void 0:o.cognitiveRelevanceScore)&&void 0!==i?i:null==r?void 0:r.cognitiveRelevanceScore;if(null!=u){var x=(c=u)>=90?{score:1,relation:"exact_match"}:c>=70?{score:.8,relation:"high_match"}:c>=40?{score:.5,relation:"partial_match"}:{score:0,relation:"no_deviation"};return f(x.score,x.relation,!0,$)}var g=s?o.relation:l?r.relation:d.relation,p=null!==(t=null==o?void 0:o.score)&&void 0!==t?t:null==r?void 0:r.score,h="number"==typeof p?p:d.score;return f(h,g,!0,$)},[be,ye,$,Xe]),Qe=i.useCallback(function(){var e,n,i;if(!Y.current){Y.current=!0;try{if(!De.current)return;var t=De.current.getBoundingClientRect(),o=[];Ne.forEach(function(e){var n=e.key,i=e.analysisKey,r=Ue.current[n],s=Ke.current[n];if((null==r?void 0:r.current)&&(null==s?void 0:s.current)){r.current.style.height="auto",s.current.style.height="auto",r.current.style.minHeight="0px",s.current.style.minHeight="0px";var l=r.current.getBoundingClientRect().height,a=s.current.getBoundingClientRect().height,c=Math.max(l,a);r.current.style.minHeight="".concat(c,"px"),s.current.style.minHeight="".concat(c,"px");var d=r.current.getBoundingClientRect(),u=s.current.getBoundingClientRect(),x=Xe(i),g=f(x.score,x.relation,x.hasContent,$);if(!g)return;var p=d.top+d.height/2-t.top;o.push({id:"field-".concat(n),x1:d.right-t.left,y1:p,x2:u.left-t.left,y2:p,style:g})}});for(var r=Math.min(be.length,ye.length),s=0;s<r;s+=1){var l=Ge.current[s],a=Ye.current[s];if((null==l?void 0:l.current)&&(null==a?void 0:a.current)){l.current.style.height="auto",a.current.style.height="auto",l.current.style.minHeight="0px",a.current.style.minHeight="0px";var c=Math.max(l.current.getBoundingClientRect().height,a.current.getBoundingClientRect().height);l.current.style.minHeight="".concat(c,"px"),a.current.style.minHeight="".concat(c,"px");var d=l.current.querySelector(".MuiAccordionSummary-root"),u=a.current.querySelector(".MuiAccordionSummary-root");if(d&&u){var x=d.getBoundingClientRect(),g=u.getBoundingClientRect(),p=(x.top+x.height/2-t.top+g.top+g.height/2-t.top)/2,h=(null===(e=ye[s])||void 0===e?void 0:e.id)||"sec-".concat(s),v=$e(s);v&&o.push({id:h,x1:x.right-t.left,y1:p,x2:g.left-t.left,y2:p,style:v,sectionIdx:s,hasCognitive:!(!(null===(n=be[s])||void 0===n?void 0:n.cognitiveData)&&!(null===(i=ye[s])||void 0===i?void 0:i.cognitiveData))})}}}if(Ie(o),ke.current&&Re.current){var _=ke.current.getBoundingClientRect(),m=Re.current.getBoundingClientRect(),b=(_.top+_.height/2-t.top+m.top+m.height/2-t.top)/2;Le({x1:_.right-t.left,x2:m.left-t.left,y:b})}else Le(null)}catch(e){console.error("Line render safe fail: ",e)}finally{Y.current=!1}}},[Ne,be,ye,$,Xe,$e]);i.useEffect(function(){var e=setTimeout(Qe,250);window.addEventListener("resize",Qe);var n=null;return K.current&&(n=new ResizeObserver(function(){return window.requestAnimationFrame(Qe)})).observe(K.current),function(){clearTimeout(e),window.removeEventListener("resize",Qe),null==n||n.disconnect()}},[Z,ve,we,se,Ne,xe,be,ye,$,Qe]);var Ze=function(i,r,s,l){var a=!j(i.title)&&!j(i.content);return n.jsx(t.Box,e.__assign({ref:l,sx:{mb:1,minHeight:0,display:"flex",flexDirection:"column"}},{children:n.jsxs(t.Accordion,e.__assign({disableGutters:!0,expanded:!a&&!!xe[r],onChange:function(){return!a&&(n=r,void ge(function(i){var t;return e.__assign(e.__assign({},i),((t={})[n]=!i[n],t))}));var n},sx:{boxShadow:"none",border:a?"1px dashed #E2E8F0":"1px solid #E2E8F0",bgcolor:a?"#FAFAFA":"#FFFFFF",borderRadius:"6px",flex:1,display:"flex",flexDirection:"column","&:before":{display:"none"}}},{children:[n.jsx(t.AccordionSummary,e.__assign({expandIcon:a?null:n.jsx(o.ChevronDown,{size:16}),sx:{minHeight:"36px",flexShrink:0,cursor:a?"default":"pointer","& .MuiAccordionSummary-content":{my:.5,display:"flex",alignItems:"center",overflow:"hidden"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"12px",color:a?"#94A3B8":"#19213D",fontWeight:a?400:700,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},{children:h(i.title||"No Matching Section Found")}))})),!a&&n.jsxs(t.AccordionDetails,e.__assign({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column"}},{children:[n.jsx(t.Typography,e.__assign({component:"div",sx:p},{children:n.jsx(x.default,{children:g(i.content).replace(/\\n/g,"\n")})})),(i.subsections||[]).map(function(i,o){return n.jsx(t.Box,e.__assign({sx:{mt:1,pt:1,borderTop:"1px solid #EEF2F7"}},{children:n.jsx(t.Typography,e.__assign({component:"div",sx:p},{children:n.jsx(x.default,{children:g(i).replace(/\\n/g,"\n")})}))}),"".concat(s,"-sub-").concat(r,"-").concat(o))})]}))]}))}),"".concat(s,"-sec-").concat(r))};return n.jsxs(t.Box,e.__assign({ref:G,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[V.open&&n.jsx(y,{open:V.open,popupRef:q,position:M,onClose:function(){O(null),N(function(n){return e.__assign(e.__assign({},n),{open:!1})})},sectionTitle:V.sectionTitle,referenceSectionTitle:V.refSectionTitle,cognitiveData:V.cognitiveData,anchorEl:V.anchorEl,sectionAnchorEl:V.sectionAnchorEl,scrollContainerEl:K.current,badgeStyle:V.badgeStyle}),n.jsx(t.Snackbar,e.__assign({open:!!I,autoHideDuration:8e3,onClose:function(){return z(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:n.jsx(t.Alert,e.__assign({onClose:function(){return z(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:I}))})),he.length>1&&n.jsxs(t.Box,e.__assign({sx:{px:3,pb:.25},ref:L},{children:[n.jsxs(t.Box,e.__assign({sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1}},{children:[n.jsx(t.Typography,e.__assign({sx:{fontSize:"13px",color:"#475569"}},{children:"Choose the Learning you want to compare with the rule you are creating."})),n.jsxs(t.Box,e.__assign({sx:{display:"flex",gap:.5,flexShrink:0,ml:1}},{children:[n.jsx(t.IconButton,e.__assign({onClick:function(){return pe("left")},size:"small",disabled:!Me},{children:n.jsx(o.ArrowLeft,{size:18})})),n.jsx(t.IconButton,e.__assign({onClick:function(){return pe("right")},size:"small",disabled:!Pe},{children:n.jsx(o.ArrowRight,{size:18})}))]}))]})),n.jsx(t.Box,e.__assign({ref:U,sx:{display:"flex",gap:1,overflowX:"auto",pb:.05,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"transparent",borderRadius:"10px"}}},{children:he.map(function(e){return n.jsx(F,{data:e,isSelected:(null==fe?void 0:fe.id)===e.id,isCognitiveOpen:se,onToggleCognitive:function(){return le(function(e){return!e})},onClick:function(){return oe((n=e).id),k(n),void le(!1);var n}},e.id)})}))]})),n.jsx(t.Box,e.__assign({ref:K,sx:{flex:1,overflowY:"auto",minHeight:0,pt:1.5,pb:8,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",borderTop:Be&&je&&se?"none":"1.5px solid #EEF0F4"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"}},{children:n.jsxs(t.Box,e.__assign({ref:De,sx:{display:"grid",gridTemplateColumns:"1fr auto 1fr",gap:"60px",maxWidth:"1200px",width:"100%",position:"relative"}},{children:[n.jsxs("svg",e.__assign({style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10}},{children:[We&&n.jsxs("g",{children:[n.jsx("line",{x1:We.x1,y1:We.y,x2:Math.max(We.x1,(We.x1+We.x2)/2-70),y2:We.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),n.jsx("line",{x1:Math.min(We.x2,(We.x1+We.x2)/2+70),y1:We.y,x2:We.x2,y2:We.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),Te.map(function(i,r){var s=(i.x1+i.x2)/2;return"Not Defined"!==i.style.label||i.hasCognitive?n.jsxs("g",{children:[n.jsx("line",{x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,stroke:i.style.badgeBorder,strokeWidth:"1.5"}),n.jsx("foreignObject",e.__assign({x:s-75,y:i.y1-14,width:"150",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:n.jsxs(t.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:i.style.badgeBg,color:i.style.badgeText,border:"1px solid ".concat(i.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:500,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"}},{children:[i.style.label,n.jsxs(t.Box,e.__assign({onClick:function(n){if(n.stopPropagation(),V.open&&V.sectionIdx===i.sectionIdx)return O(null),void N(function(n){return e.__assign(e.__assign({},n),{open:!1})});!function(e,n,i,t,o){var r,s;e.stopPropagation(),O(null);var l=g(n.id)||g(i.id)||"",a=(l?W[l]:null)||n.cognitiveData||i.cognitiveData||null,c=null!==(s=null===(r=Ce.current[t])||void 0===r?void 0:r.current)&&void 0!==s?s:null;N({open:!0,sectionTitle:n.title||"Section",refSectionTitle:i.title||"Reference Section",cognitiveData:a,anchorEl:e.currentTarget,sectionAnchorEl:c,badgeStyle:o||null,sectionIdx:t})}(n,be[i.sectionIdx]||{title:"",content:""},ye[i.sectionIdx]||{title:"",content:""},i.sectionIdx,i.style)}},{children:[i.hasCognitive&&void 0!==i.sectionIdx&&n.jsx(t.Box,e.__assign({sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"4px",px:"4px",ml:"2px",color:i.style.badgeText,transition:"background 0.15s"}},{children:n.jsx("div",e.__assign({style:{width:"13px",height:"13px",display:"flex",alignItems:"center",marginRight:"2px"}},{children:n.jsx(l.ButtonCognitiveIcon,{})}))})),V.open&&V.sectionIdx===i.sectionIdx?n.jsx(o.ChevronUp,{size:12,color:i.style.badgeText}):n.jsx(o.ChevronDown,{size:12,color:i.style.badgeText})]}))]}))}))}))]},r):null})]})),n.jsxs(t.Box,e.__assign({sx:{border:"1px dashed #B0B0B0",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)",minWidth:0}},{children:[n.jsx(t.Box,e.__assign({ref:ke,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px dashed #B0B0B0",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"24px",alignItems:"center"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#19213D"}},{children:_e}))})),n.jsxs(t.Box,e.__assign({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[Ne.map(function(e){var i=e.key,t=e.label,o=e.analysisKey,r=Xe(o),s=Z[i],l=ve[i];if(!j(s)&&!j(l))return null;var a=f(r.score,r.relation,r.hasContent,$);return a?n.jsx(_,{ref:Ue.current[i],label:t,content:s,highlights:r.highlightsA,styleVariant:a,isHighlighted:ce===o||ce===i},"left-".concat(i)):null}),Fe&&be.map(function(e,n){return{section:e,idx:n}}).map(function(i){var o=i.section,r=i.idx;return n.jsx(t.Box,e.__assign({ref:Se(r)},{children:Ze(o,r,"left",Ge.current[r]||d.default.createRef())}),"left-row-".concat(r))})]}))]})),n.jsx(t.Box,e.__assign({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"6px",gap:0}},{children:n.jsx(t.Box,e.__assign({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:n.jsxs(t.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(t.Box,e.__assign({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:n.jsx(l.ButtonCognitiveIcon,{})})),Ee,"% Similarity",n.jsx(o.ChevronDown,{size:11})]}))}))})),n.jsxs(t.Box,e.__assign({sx:{border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0}},{children:[n.jsx(t.Box,e.__assign({ref:Re,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"24px",display:"flex",alignItems:"center"}},{children:n.jsx(t.Typography,e.__assign({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",display:"flex",alignItems:"center",gap:1}},{children:me}))})),n.jsxs(t.Box,e.__assign({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[Ne.map(function(e){var i=e.key,t=e.label,o=e.analysisKey,r=Xe(o),s=Z[i],l=ve[i];if(!j(s)&&!j(l))return null;var a=f(r.score,r.relation,r.hasContent,$);return a?n.jsx(_,{ref:Ke.current[i],label:t,content:l,highlights:r.highlightsB,styleVariant:a,isHighlighted:ce===o||ce===i},"right-".concat(i)):null}),Fe&&ye.map(function(e,n){return{section:e,idx:n}}).map(function(e){var n=e.section,i=e.idx;return Ze(n,i,"right",Ye.current[i]||d.default.createRef())})]}))]}))]}))}))}))]}))};
2
2
  //# sourceMappingURL=CognitiveCompare.js.map
@@ -1,2 +1,2 @@
1
- import{__assign as e,__spreadArray as n}from"tslib";import{jsxs as t,jsx as i,Fragment as r}from"react/jsx-runtime";import o,{useState as l,useMemo as a,useRef as c,useCallback as s,useEffect as d}from"react";import{Box as u,Typography as p,Snackbar as h,Alert as g,IconButton as f,Skeleton as x,Accordion as v,AccordionSummary as m,AccordionDetails as b}from"@mui/material";import{ArrowLeft as y,ArrowRight as F,ChevronUp as w,ChevronDown as E,X as C}from"lucide-react";import S from"react-dom";import k from"../../assests/svg/SparkleIcon.js";import{ButtonCognitiveIcon as D}from"../../assests/svg/ButtonCognitiveIcon.js";import B from"react-markdown";var A=function(e){return null==e?"":"string"==typeof e?e:Array.isArray(e)?e.map(A).join("\n\n"):"object"==typeof e?JSON.stringify(e):String(e)},R=function(e){return e?A(e).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,n){return e.startsWith("**")&&e.endsWith("**")?i("strong",{children:e.slice(2,-2)},n):i(o.Fragment,{children:e},n)}):null},I=function(n,t,i,r){var o=100*(n||0),l=r.thresholds,a=r.relationStyles;if(!i)return null;var c=function(e){return e&&"string"==typeof e?e.split("_").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}).join(" "):"Unknown"}(t),s=(t||"").toLowerCase();return s.includes("no_deviation")?e(e({},a.low),{label:c}):s.includes("deviation")||s.includes("high_risk")||s.includes("critical")?e(e({},a.high),{label:c}):o>=l.exact?e(e({},a.exact),{label:c}):o>=l.high?e(e({},a.high),{label:c}):o>=l.medium?e(e({},a.medium),{label:c}):e(e({},a.low),{label:c})},_=o.forwardRef(function(n,r){var l=n.label,a=n.content,c=n.highlights,s=void 0===c?[]:c,d=n.styleVariant,h=n.isHighlighted,g=void 0!==h&&h,f=Array.isArray(a)?a.map(A).join("\n"):A(a),x="#9F1239"===d.badgeText?{borderColor:"#E11D48",shadow:"rgba(225, 29, 72, 0.25)"}:"#B91C1C"===d.badgeText?{borderColor:"#EF4444",shadow:"rgba(239, 68, 68, 0.25)"}:"#1D4ED8"===d.badgeText?{borderColor:"#3B82F6",shadow:"rgba(59, 130, 246, 0.25)"}:"#A16207"===d.badgeText?{borderColor:"#F59E0B",shadow:"rgba(245, 158, 11, 0.25)"}:{borderColor:"#6366F1",shadow:"rgba(99, 102, 241, 0.25)"};return t(u,e({sx:{mb:1.5}},{children:[i(p,e({sx:{fontSize:"12px",color:"#19213D",mb:.5,fontWeight:500}},{children:l})),i(u,e({ref:r,sx:{p:"4px 12px",borderRadius:"6px",border:g?"1.5px solid ".concat(x.borderColor):"1px solid ".concat(d.border),boxShadow:g?"0px 0px 0px 2px ".concat(x.shadow):"none",bgcolor:d.bg,fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,minHeight:"24px",display:"flex",alignItems:"center",whiteSpace:"pre-line",wordBreak:"break-word"}},{children:i(u,{children:function(){if(!f)return null;if(!s||0===s.length)return R(f);var n=s.filter(function(e){return e&&"string"==typeof e&&e.length>0}).map(function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")});if(0===n.length)return R(f);var t=new RegExp("(".concat(n.join("|"),")"),"gi");return f.split(t).map(function(n,t){return s.some(function(e){return e&&"string"==typeof e&&e.toLowerCase()===n.toLowerCase()})?i(u,e({component:"span",sx:{bgcolor:d.highlightBg,borderRadius:"2px",px:"2px"}},{children:R(n)}),t):i(o.Fragment,{children:R(n)},t)})}()})}))]}))}),z=10,W=function(n){var o,c,s,h,g,x,v,m=n.open,b=n.onClose,y=n.sectionTitle,F=n.referenceSectionTitle,w=n.cognitiveData,D=n.relevanceScore,B=n.anchorEl,R=n.badgeStyle,I=n.popupRef,_=n.position,W=l("association"),T=W[0],L=W[1],H=a(function(){if(!R)return{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"};var e=R.badgeText;return"#9F1239"===e||"#B42318"===e?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===e?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===e?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"}},[R]);if(d(function(){if(m){var e=function(e){var n;(null===(n=I.current)||void 0===n?void 0:n.contains(e.target))||(null==B?void 0:B.contains(e.target))||b()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[m,b,B,I]),!m||!w)return null;var j=null!==(c=null!==(o=w.relevance_score)&&void 0!==o?o:D)&&void 0!==c?c:0,M=function(e){return e?e.split(/(?<=\.)(?:\s+(?=[A-Z])|\s+\d+\.\s)/).map(function(e){return e.trim()}).filter(function(e){return e.length>10}):[]},O=M(null!==(s=w.decisioning)&&void 0!==s?s:""),P=M(null!==(h=w.gap)&&void 0!==h?h:""),V=function(e){if(!e)return[];if(Array.isArray(e))return e.flatMap(function(e){if("string"==typeof e)return[{key:"metadata",value:e}];if("object"==typeof e&&null!==e){var n=e,t={key:A(n.key),value:A(n.value),url:A(n.url)};return t.value||t.key||t.url?[t]:[]}return[]});if("string"==typeof e)return[{key:"metadata",value:e}];if("object"==typeof e){var n=e;if("value"in n||"key"in n||"url"in n)return[{key:A(n.key),value:A(n.value),url:A(n.url)}]}return[]},K=function(e,n){var t,i,r=w,o="decisioning"===e?null!==(t=r.decisioning_metadata)&&void 0!==t?t:r.decisioningMetadata:null!==(i=r.gap_metadata)&&void 0!==i?i:r.gapMetadata;if(Array.isArray(o)){if((d=V(o[n])).length)return d;if((u=V(o)).length)return u}else{var l=V(o);if(l.length)return l}var a=r.metadata;if(a&&"object"==typeof a&&!Array.isArray(a)){var c=a,s="decisioning"===e?c.decisioning:c.gap;if(Array.isArray(s)){var d,u;if((d=V(s[n])).length)return d;if((u=V(s)).length)return u}else{var p=V(s);if(p.length)return p}}return[]},N=function(n){if(!n.length)return null;var r=n[0],o=r.key||"metadata",l=r.value||r.url||"",a=l?"".concat(o,": ").concat(l):o;return t(u,e({component:"span",sx:{display:"inline-flex",alignItems:"center",color:"#253AE4",fontWeight:600,ml:.5,whiteSpace:"nowrap"}},{children:["(",a,i(E,{size:13,style:{marginLeft:2}}),")"]}))},U=null!==(g=null==_?void 0:_.arrowLeft)&&void 0!==g?g:60,q=t(u,e({ref:I,sx:{position:"fixed",top:null!==(x=null==_?void 0:_.top)&&void 0!==x?x:-9999,left:null!==(v=null==_?void 0:_.left)&&void 0!==v?v:-9999,zIndex:9999,width:"min(".concat(680,"px, calc(100vw - ").concat(24,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat(H.border),boxShadow:"0px 8px 32px ".concat(H.shadow,", 0px 0px 0px 3px ").concat(H.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:"60vh",visibility:_?"visible":"hidden"}},{children:[_&&(_.openAbove?t(r,{children:[i(u,{sx:{position:"absolute",bottom:-11,left:U-z,width:0,height:0,borderLeft:"".concat(z,"px solid transparent"),borderRight:"".concat(z,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat(H.border),zIndex:1}}),i(u,{sx:{position:"absolute",bottom:-9,left:U-z+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(z,"px solid #FFFFFF"),zIndex:2}})]}):t(r,{children:[i(u,{sx:{position:"absolute",top:-11,left:U-z,width:0,height:0,borderLeft:"".concat(z,"px solid transparent"),borderRight:"".concat(z,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat(H.border),zIndex:1}}),i(u,{sx:{position:"absolute",top:-9,left:U-z+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(z,"px solid #FFFFFF"),zIndex:2}})]})),t(u,e({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[t(u,e({sx:{flex:1,minWidth:0}},{children:[t(p,e({sx:{fontSize:"18px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden"}},{children:[i(u,e({component:"span",title:y,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:y})),i(u,e({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),i(u,e({component:"span",title:F||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:F||"Reference Section"}))]})),i(u,e({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:i(p,e({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:"Why this is a Deviation?"}))}))]})),t(u,e({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[t(u,e({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:[i(k,{}),"Decision Strength ",j,"%"]})),i(f,e({onClick:b,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:i(C,{size:22})}))]}))]})),i(u,e({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:["deviation","association"].map(function(n){var t=T===n;return i(u,e({onClick:function(){return L(n)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:t?600:400,color:t?"#5928ED":"#667085",backgroundColor:t?"rgba(89,40,237,0.08)":"transparent",borderBottom:t?"2px solid #5928ED":"2px solid transparent",transition:"all 0.15s",userSelect:"none",overflowY:"auto"}},{children:"deviation"===n?"Deviation Analysis":"Association Logic"}),n)})})),i(u,e({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(H.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:H.border},scrollbarWidth:"thin",scrollbarColor:"".concat(H.border,"55 transparent")}},{children:"deviation"===T?t(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD",p:2,display:"flex",flexDirection:"column",gap:1}},{children:[i(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054"}},{children:"Deviation Analysis"})),i(p,e({sx:{fontSize:"14px",color:"#667085",lineHeight:1.6}},{children:"Deviation analysis content will appear here. This tab shows structural and semantic deviations identified between the two sections being compared."}))]})):t(r,{children:[O.length>0&&t(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[i(u,e({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:i(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Decision Making Factors"}))})),i(u,e({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:O.map(function(n,i){return t(p,e({sx:{fontSize:"14px",color:"#344054",lineHeight:1.55,wordBreak:"break-word"}},{children:[i+1,". ",n,N(K("decisioning",i))]}),i)})}))]})),P.length>0&&t(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[i(u,e({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:i(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Gaps in Decision"}))})),i(u,e({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:P.map(function(n,i){return t(p,e({sx:{fontSize:"14px",color:"#344054",lineHeight:1.55,wordBreak:"break-word"}},{children:[i+1,". ",n,N(K("gap",i))]}),i)})}))]})),0===O.length&&0===P.length&&i(u,e({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:i(p,e({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]})}))]}));return S.createPortal(q,document.body)},T=function(n){var r=n.data,o=n.isSelected,l=n.isCognitiveOpen,a=n.onToggleCognitive,c=n.onClick,s=A(r.summaryText||r.description),d=s.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),h=d?s.replace(d[0],"").trim():s,g=!!d;return t(u,e({id:"variant-card-".concat(r.id),onClick:c,sx:{minWidth:"280px",maxWidth:"280px",p:2,m:.5,bgcolor:o?"#EFF6FF99":"#FFFFFF",borderRadius:"8px",cursor:"pointer",transition:"all 0.2s",display:"flex",flexDirection:"column",gap:1,flexShrink:0,opacity:r.isLoading?.7:1,border:o?"1.4px solid #2563EB":void 0,boxShadow:o?"none":"0px 2px 4px 0px #19213D14","&:hover":{borderColor:o?"#2563EB":"#CBD5E1",boxShadow:o?"none":"0px 4px 8px 0px #19213D1F"}}},{children:[i(u,e({sx:{display:"flex",alignItems:"center",gap:1.5}},{children:r.isLoading?i(x,{variant:"rounded",width:80,height:20}):t(u,e({sx:{bgcolor:"#FEF2F2",color:"#B91C1C",fontSize:"11px",fontWeight:600,px:1,py:.5,borderRadius:"100px",border:"1px solid #FFE1E1"}},{children:[void 0!==r.similarity?r.similarity:0,"% Similarity"]}))})),t(u,e({sx:{display:"flex",flexDirection:"column",gap:1}},{children:[i(u,e({sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap"}},{children:i(p,e({sx:{fontWeight:500,fontSize:"14px",color:"#19213D",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"}},{children:A(r.title)}))})),r.isLoading?t(u,{children:[i(x,{width:"90%"}),i(x,{width:"60%"})]}):t(u,e({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[i(p,e({sx:{fontWeight:400,fontSize:"13px",color:"#666F8D",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"}},{children:h})),g&&t(u,e({onClick:function(e){e.stopPropagation(),o||c(),a()},sx:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",cursor:"pointer",marginLeft:"-4px","&:hover":{backgroundColor:"#F1F5F9"}}},{children:[i("div",e({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:i(D,{})})),i(E,{size:12,style:{transform:o&&l?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}))]}))]}))]}))},L=[{key:"title",label:"Title",analysisKey:"title"},{key:"description",label:"Description",analysisKey:"description"}],H={fields:L,thresholds:{exact:90,high:70,medium:40},relationStyles:{noContent:{bg:"#FFFFFF",border:"#E2E8F0",badgeBg:"#F8FAFC",badgeBorder:"#F1F5F9",badgeText:"#64748B",highlightBg:"transparent"},exact:{bg:"#FFF1F2",border:"#FECDD3",badgeBg:"#FFE4E6",badgeBorder:"#FEE2E2",badgeText:"#9F1239",highlightBg:"#FECDD3"},high:{bg:"#FFF5F5",border:"#FECACA",badgeBg:"#FEECEC",badgeBorder:"#F8C2C2",badgeText:"#B42318",highlightBg:"#FDD5D5"},medium:{bg:"#FFFCF6",border:"#FFDD80",badgeBg:"#FEF9C3",badgeBorder:"#FEF08A",badgeText:"#A16207",highlightBg:"#FDDEB3"},low:{bg:"#F5F9FF",border:"#CFE0FF",badgeBg:"#EEF4FF",badgeBorder:"#BFD3FF",badgeText:"#1D4ED8",highlightBg:"#DCEAFF"}}},j=function(e){return null!=e&&("string"==typeof e?e.trim().length>0:!Array.isArray(e)||e.length>0&&e.some(function(e){return j(e)}))},M=function(n){var t,i,r,o,l=[],a=[],c=n.base_root_id,s=n.input_index_map||{0:"left",1:"right"},d=n[c];if(!d||!1===d.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var u=function(e,n){var t,i=s[n],r=null===(t=null==e?void 0:e.comparison_inputs)||void 0===t?void 0:t[i];return{title:A((null==r?void 0:r.title)||""),content:A((null==r?void 0:r.content)||"")}};d.next&&Object.values(d.next).forEach(function(t){var i=n[t];if(i&&!1!==i.display_node){var r=function(e){if(!e.mapping_rationale)return{score:void 0,relation:"not_defined"};var n=e.mapping_rationale,t=!n.decision_strength,i=parseInt(n.decision_strength||"0");return{cognitiveData:{decisioning:n.decisioning_factors||"",gap:n.gaps_in_decision||"",relevance_score:i},score:t?100:i/100,relation:i>=70?"no_deviation":"deviation"}}(i),o=u(i,"0"),c=u(i,"1"),s=e({id:t,title:o.title,content:o.content,subsections:[]},r),d=e({id:t,title:c.title,content:c.content,subsections:[]},r);if(i.next)Object.values(i.next).forEach(function(e){var t=n[e];if(t&&!1!==t.display_node){var i=u(t,"0"),r=u(t,"1");i.content&&s.subsections.push(i.content),r.content&&d.subsections.push(r.content)}});l.push(s),a.push(d)}});return{activeProposed:{title:(null===(i=null===(t=d.comparison_inputs)||void 0===t?void 0:t[s[0]])||void 0===i?void 0:i.title)||"Uploaded Contract",description:d.decision_scope_description||"",sections:l},activeVariants:[{id:"tree-variant-1",title:(null===(o=null===(r=d.comparison_inputs)||void 0===r?void 0:r[s[1]])||void 0===o?void 0:o.title)||"Reference Template",similarity:0,sections:a,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:d.decision_scope_description||""},fields:{}}}}]}},O=function(r){var x,C,S,k=r.variants,O=void 0===k?[]:k,P=r.treeData,V=r.comparisonConfig,K=r.onSelectVariant;r.onSkip,r.onBack;var N=r.targetVariantId,U=r.highlightedField;r.onBadgeClick,r.activeBadgeId;var q=l(null),Y=q[0],G=q[1],J=a(function(){return(null==P?void 0:P.cognitive_decisioning)||{}},[P]),$=c(null),X=l(null),Z=X[0],Q=X[1],ee=c(null),ne=l({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null}),te=ne[0],ie=ne[1],re=c(null),oe=c(null),le=c(null),ae=c(!1),ce=s(function(){var e;if(te.anchorEl&&te.refSectionTitle){var n=te.anchorEl.getBoundingClientRect(),t=(null===(e=null==ee?void 0:ee.current)||void 0===e?void 0:e.offsetHeight)||0,i=Math.min(680,window.innerWidth-24),r=window.innerHeight-n.bottom-12,o=n.top-12,l=r<t&&o>r,a=l?n.top-12-t:n.bottom+12,c=n.left+n.width/2,s=c-i/2,d=Math.max(12,Math.min(s,window.innerWidth-i-12)),u=Math.max(14,Math.min(c-d,i-z-4));Q({top:a,left:d,arrowLeft:u,openAbove:l})}},[te.anchorEl,te.refSectionTitle]);d(function(){if(te.open){window.addEventListener("resize",ce);var e=requestAnimationFrame(ce);return function(){cancelAnimationFrame(e),window.removeEventListener("resize",ce)}}},[te.open,ce]),d(function(){var n=oe.current;if(n&&te.open){var t=function(n){console.log("Scroll event detected on:",n.target,"- closing CognitivePopup"),ie(function(n){return e(e({},n),{open:!1,anchorEl:null,sectionAnchorEl:null})})};return n.addEventListener("scroll",t,{capture:!0}),window.addEventListener("scroll",t,{capture:!0}),function(){n.removeEventListener("scroll",t,{capture:!0}),window.removeEventListener("scroll",t,{capture:!0})}}},[te.open]);var se=a(function(){var n,t,i,r,o,l,a,c,s,d,u,p;return{fields:null!==(n=null==V?void 0:V.fields)&&void 0!==n?n:L,thresholds:{high:null!==(i=null===(t=null==V?void 0:V.thresholds)||void 0===t?void 0:t.high)&&void 0!==i?i:H.thresholds.high,medium:null!==(o=null===(r=null==V?void 0:V.thresholds)||void 0===r?void 0:r.medium)&&void 0!==o?o:H.thresholds.medium,exact:null!==(a=null===(l=null==V?void 0:V.thresholds)||void 0===l?void 0:l.exact)&&void 0!==a?a:H.thresholds.exact},relationStyles:{noContent:e(e({},H.relationStyles.noContent),(null===(c=null==V?void 0:V.relationStyles)||void 0===c?void 0:c.noContent)||{}),high:e(e({},H.relationStyles.high),(null===(s=null==V?void 0:V.relationStyles)||void 0===s?void 0:s.high)||{}),exact:e(e({},H.relationStyles.exact),(null===(d=null==V?void 0:V.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e(e({},H.relationStyles.medium),(null===(u=null==V?void 0:V.relationStyles)||void 0===u?void 0:u.medium)||{}),low:e(e({},H.relationStyles.low),(null===(p=null==V?void 0:V.relationStyles)||void 0===p?void 0:p.low)||{})}}},[V]),de=a(function(){if(P&&Object.keys(P).length>0)try{var n=M(P);return e(e({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:O||[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:O||[],parseError:null}},[P,O]),ue=de.activeProposed,pe=de.activeVariants,he=de.parseError;d(function(){he&&G("Failed to load comparison: ".concat(he))},[he]);var ge=l(N||null),fe=ge[0],xe=ge[1],ve=l(!1),me=ve[0],be=ve[1],ye=l(null),Fe=ye[0],we=ye[1],Ee=l({}),Ce=Ee[0],Se=Ee[1];d(function(){if(N&&xe(N),we(null!=U?U:null),U){var e=setTimeout(function(){return we(null)},6e3);return function(){return clearTimeout(e)}}},[N,U]);var ke=function(e){var n;null===(n=re.current)||void 0===n||n.scrollBy({left:"left"===e?-300:300,behavior:"smooth"})},De=a(function(){return n([],pe,!0).sort(function(e,n){return(n.similarity||0)-(e.similarity||0)})},[pe]),Be=a(function(){if(fe){var e=String(fe).trim();return pe.find(function(n){return n.id&&String(n.id).trim()===e})||De[0]}return De[0]||null},[fe,pe,De]);d(function(){fe&&re.current&&setTimeout(function(){var e=document.getElementById("variant-card-".concat(fe.trim())),n=re.current;if(e&&n){var t=e.offsetLeft-n.offsetLeft-n.clientWidth/2+e.clientWidth/2;n.scrollTo({left:t,behavior:"smooth"})}},150)},[fe,De]);var Ae=Be||{id:"",title:""},Re=A(ue.title)||"Uploaded Contract",Ie=A(Ae.title)||"Reference Template",_e=ue.sections||[],ze=Ae.sections||[],We=_e.length>0||ze.length>0,Te=null==Be?void 0:Be.analysis,Le=A(null===(C=null===(x=null==Te?void 0:Te.rule_difference_comparison)||void 0===x?void 0:x.summary)||void 0===C?void 0:C.overall_summary),He=!!Le.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),je=null!==(S=null==Be?void 0:Be.similarity)&&void 0!==S?S:0,Me=c({}),Oe=function(e){return Me.current[e]||(Me.current[e]=o.createRef()),Me.current[e]};d(function(){!fe&&!N&&De.length>0&&!De[0].isLoading&&xe(De[0].id)},[De,fe,N]);var Pe=c(null),Ve=c(null),Ke=c(null),Ne=l([]),Ue=Ne[0],qe=Ne[1],Ye=l(null),Ge=Ye[0],Je=Ye[1],$e=l(!1),Xe=$e[0],Ze=$e[1],Qe=l(!1),en=Qe[0],nn=Qe[1];d(function(){var e=re.current;if(e){var n=function(){Ze(e.scrollLeft>0),nn(e.scrollLeft+e.clientWidth<e.scrollWidth-1)};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),function(){e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}}},[De]);var tn=a(function(){return se.fields.filter(function(e){var n=e.key;return(!We||"description"!==n)&&(j(ue[n])||j(Ae[n]))})},[ue,Ae,We,se.fields]),rn=c({}),on=c({}),ln=c({}),an=c({});tn.forEach(function(e){var n=e.key;rn.current[n]||(rn.current[n]=o.createRef()),on.current[n]||(on.current[n]=o.createRef())});for(var cn=0;cn<Math.max(_e.length,ze.length);cn+=1)ln.current[cn]||(ln.current[cn]=o.createRef()),an.current[cn]||(an.current[cn]=o.createRef());d(function(){if(Fe){var e=se.fields.find(function(e){return e.analysisKey===Fe||e.key===Fe});if(e){var n=rn.current[e.key]||on.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[Fe,se.fields]);var sn=function(e){var n,t,i,r,o,l,a,c,s,d=null===(n=null==Te?void 0:Te.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!d||!d[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var u=d[e],p=(null==u?void 0:u.relation)||(null===(i=null===(t=null==u?void 0:u.highlights)||void 0===t?void 0:t.ruleA_spans)||void 0===i?void 0:i.length)||(null===(o=null===(r=null==u?void 0:u.highlights)||void 0===r?void 0:r.ruleB_spans)||void 0===o?void 0:o.length)||(null==u?void 0:u.mappings)&&u.mappings.length>0;if(u.mappings){var h=u.mappings[0]||{};return{score:u.score,relation:h.relation||"",highlightsA:(null===(l=h.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(a=h.highlights)||void 0===a?void 0:a.ruleB_spans)||[],hasContent:!!p}}return{score:u.score,relation:u.relation||"",highlightsA:(null===(c=u.highlights)||void 0===c?void 0:c.ruleA_spans)||[],highlightsB:(null===(s=u.highlights)||void 0===s?void 0:s.ruleB_spans)||[],hasContent:!!p}},dn=function(n){var t=ze[n];if("not_defined"===(null==t?void 0:t.relation))return e(e({},se.relationStyles.noContent),{label:"Not Defined"});var i,r=sn("description");if(null!=(null==t?void 0:t.cognitiveRelevanceScore)){var o=(i=t.cognitiveRelevanceScore)>=90?{score:1,relation:"exact_match"}:i>=70?{score:.8,relation:"high_match"}:i>=40?{score:.5,relation:"partial_match"}:{score:0,relation:"no_deviation"};return I(o.score,o.relation,!0,se)}var l=null!=(null==t?void 0:t.relation)&&""!==t.relation?t.relation:r.relation,a="number"==typeof(null==t?void 0:t.score)?t.score:r.score;return I(a,l,!0,se)},un=function(){var e,n,t;if(!ae.current){ae.current=!0;try{if(!Pe.current)return;var i=Pe.current.getBoundingClientRect(),r=[];tn.forEach(function(e){var n=e.key,t=e.analysisKey,o=rn.current[n],l=on.current[n];if((null==o?void 0:o.current)&&(null==l?void 0:l.current)){o.current.style.height="auto",l.current.style.height="auto",o.current.style.minHeight="0px",l.current.style.minHeight="0px";var a=o.current.getBoundingClientRect().height,c=l.current.getBoundingClientRect().height,s=Math.max(a,c);o.current.style.minHeight="".concat(s,"px"),l.current.style.minHeight="".concat(s,"px");var d=o.current.getBoundingClientRect(),u=l.current.getBoundingClientRect(),p=sn(t),h=I(p.score,p.relation,p.hasContent,se);if(!h)return;var g=d.top+d.height/2-i.top;r.push({id:"field-".concat(n),x1:d.right-i.left,y1:g,x2:u.left-i.left,y2:g,style:h})}});for(var o=Math.min(_e.length,ze.length),l=0;l<o;l+=1){var a=ln.current[l],c=an.current[l];if((null==a?void 0:a.current)&&(null==c?void 0:c.current)){a.current.style.height="auto",c.current.style.height="auto",a.current.style.minHeight="0px",c.current.style.minHeight="0px";var s=Math.max(a.current.getBoundingClientRect().height,c.current.getBoundingClientRect().height);a.current.style.minHeight="".concat(s,"px"),c.current.style.minHeight="".concat(s,"px");var d=a.current.querySelector(".MuiAccordionSummary-root"),u=c.current.querySelector(".MuiAccordionSummary-root");if(d&&u){var p=d.getBoundingClientRect(),h=u.getBoundingClientRect(),g=(p.top+p.height/2-i.top+h.top+h.height/2-i.top)/2,f=(null===(e=ze[l])||void 0===e?void 0:e.id)||"sec-".concat(l),x=dn(l);x&&r.push({id:f,x1:p.right-i.left,y1:g,x2:h.left-i.left,y2:g,style:x,sectionIdx:l,hasCognitive:!(!(null===(n=_e[l])||void 0===n?void 0:n.cognitiveData)&&!(null===(t=ze[l])||void 0===t?void 0:t.cognitiveData))})}}}if(qe(r),Ve.current&&Ke.current){var v=Ve.current.getBoundingClientRect(),m=Ke.current.getBoundingClientRect(),b=(v.top+v.height/2-i.top+m.top+m.height/2-i.top)/2;Je({x1:v.right-i.left,x2:m.left-i.left,y:b})}else Je(null)}catch(e){console.error("Line render safe fail: ",e)}finally{ae.current=!1}}};d(function(){var e=setTimeout(un,250);window.addEventListener("resize",un);var n=null;return oe.current&&(n=new ResizeObserver(function(){return window.requestAnimationFrame(un)})).observe(oe.current),function(){clearTimeout(e),window.removeEventListener("resize",un),null==n||n.disconnect()}},[ue,Ae,Te,me,tn,Ce,_e,ze,se]);var pn={fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,wordBreak:"break-word",overflowWrap:"break-word",overflow:"hidden","& p":{mt:0,mb:1.5},"& p:last-child":{mb:0},"& ul, & ol":{mt:0,mb:1.5,pl:2.5},"& li":{mb:.5},"& strong":{fontWeight:600},"& code":{whiteSpace:"pre-wrap",wordBreak:"break-word"}},hn=function(n,r,o,l){return i(u,e({ref:l,sx:{mb:1,minHeight:0,display:"flex",flexDirection:"column"}},{children:t(v,e({disableGutters:!0,expanded:!!Ce[r],onChange:function(){return n=r,void Se(function(t){var i;return e(e({},t),((i={})[n]=!t[n],i))});var n},sx:{boxShadow:"none",border:"1px solid #E2E8F0",bgcolor:"#FFFFFF",borderRadius:"6px",flex:1,display:"flex",flexDirection:"column","&:before":{display:"none"}}},{children:[i(m,e({expandIcon:i(E,{size:16}),sx:{minHeight:"36px",flexShrink:0,"& .MuiAccordionSummary-content":{my:.5,display:"flex",alignItems:"center",overflow:"hidden"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:i(p,e({sx:{fontSize:"12px",color:"#19213D",fontWeight:500,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},{children:R(n.title||"Section ".concat(r+1))}))})),t(b,e({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column"}},{children:[i(p,e({component:"div",sx:pn},{children:i(B,{children:A(n.content).replace(/\\n/g,"\n")})})),(n.subsections||[]).map(function(n,t){return i(u,e({sx:{mt:1,pt:1,borderTop:"1px solid #EEF2F7"}},{children:i(p,e({component:"div",sx:pn},{children:i(B,{children:A(n).replace(/\\n/g,"\n")})}))}),"".concat(o,"-sub-").concat(r,"-").concat(t))})]}))]}))}),"".concat(o,"-sec-").concat(r))};return t(u,e({ref:le,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[te.open&&i(W,{open:te.open,popupRef:ee,position:Z,onClose:function(){return ie(function(n){return e(e({},n),{open:!1})})},sectionTitle:te.sectionTitle,referenceSectionTitle:te.refSectionTitle,cognitiveData:te.cognitiveData,anchorEl:te.anchorEl,sectionAnchorEl:te.sectionAnchorEl,scrollContainerEl:oe.current,badgeStyle:te.badgeStyle}),i(h,e({open:!!Y,autoHideDuration:8e3,onClose:function(){return G(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:i(g,e({onClose:function(){return G(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:Y}))})),i(u,e({sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:"#FFFFFF",border:"1.5px solid #EEF0F4"}},{children:i(u,e({sx:{display:"flex",alignItems:"center",gap:1}},{children:i(p,e({sx:{fontSize:"16px",fontWeight:450,color:"#0F172A"}},{children:"Learning Comparison"}))}))})),De.length>1&&t(u,e({sx:{px:3,pb:.25},ref:$},{children:[t(u,e({sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1}},{children:[i(p,e({sx:{fontSize:"13px",color:"#475569"}},{children:"Choose the Learning you want to compare with the rule you are creating."})),t(u,e({sx:{display:"flex",gap:.5,flexShrink:0,ml:1}},{children:[i(f,e({onClick:function(){return ke("left")},size:"small",disabled:!Xe},{children:i(y,{size:18})})),i(f,e({onClick:function(){return ke("right")},size:"small",disabled:!en},{children:i(F,{size:18})}))]}))]})),i(u,e({ref:re,sx:{display:"flex",gap:1,overflowX:"auto",pb:.05,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"transparent",borderRadius:"10px"}}},{children:De.map(function(e){return i(T,{data:e,isSelected:(null==Be?void 0:Be.id)===e.id,isCognitiveOpen:me,onToggleCognitive:function(){return be(function(e){return!e})},onClick:function(){return xe((n=e).id),K(n),void be(!1);var n}},e.id)})}))]})),i(u,e({ref:oe,sx:{flex:1,overflowY:"auto",minHeight:0,pt:1.5,pb:8,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",borderTop:Le&&He&&me?"none":"1.5px solid #EEF0F4"}},{children:i(u,e({sx:{display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"}},{children:t(u,e({ref:Pe,sx:{display:"grid",gridTemplateColumns:"1fr auto 1fr",gap:"60px",maxWidth:"1200px",width:"100%",position:"relative"}},{children:[t("svg",e({style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10}},{children:[Ge&&t("g",{children:[i("line",{x1:Ge.x1,y1:Ge.y,x2:Math.max(Ge.x1,(Ge.x1+Ge.x2)/2-70),y2:Ge.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),i("line",{x1:Math.min(Ge.x2,(Ge.x1+Ge.x2)/2+70),y1:Ge.y,x2:Ge.x2,y2:Ge.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),Ue.map(function(n,r){var o=(n.x1+n.x2)/2;return n.id||"line-".concat(r),"Not Defined"===n.style.label?null:t("g",{children:[i("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke:n.style.badgeBorder,strokeWidth:"1.5"}),i("foreignObject",e({x:o-75,y:n.y1-14,width:"150",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:i(u,e({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:t(u,e({sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:n.style.badgeBg,color:n.style.badgeText,border:"1px solid ".concat(n.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:500,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"},onClick:function(e){e.stopPropagation(),function(e,n,t,i,r){var o,l;e.stopPropagation();var a=A(n.id)||A(t.id)||"",c=(a?J[a]:null)||n.cognitiveData||t.cognitiveData||null,s=null!==(l=null===(o=Me.current[i])||void 0===o?void 0:o.current)&&void 0!==l?l:null;ie({open:!0,sectionTitle:n.title||"Section",refSectionTitle:t.title||"Reference Section",cognitiveData:c,anchorEl:e.currentTarget,sectionAnchorEl:s,badgeStyle:r||null,sectionIdx:i})}(e,_e[n.sectionIdx]||{title:"",content:""},ze[n.sectionIdx]||{title:"",content:""},n.sectionIdx,n.style)}},{children:[n.style.label,n.hasCognitive&&void 0!==n.sectionIdx&&i(u,e({sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"4px",px:"4px",ml:"2px",color:n.style.badgeText,transition:"background 0.15s","&:hover":{backgroundColor:"rgba(0,0,0,0.05)"}}},{children:i("div",e({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:i(D,{})}))})),te.open&&te.sectionIdx===n.sectionIdx?i(w,{size:12,color:n.style.badgeText}):i(E,{size:12,color:n.style.badgeText})]}))}))}))]},r)})]})),t(u,e({sx:{border:"1px dashed #B0B0B0",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)",minWidth:0}},{children:[i(u,e({ref:Ve,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px dashed #B0B0B0",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"24px",alignItems:"center"}},{children:i(p,e({sx:{fontSize:"16px",fontWeight:500,color:"#19213D"}},{children:Re}))})),t(u,e({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[tn.map(function(e){var n=e.key,t=e.label,r=e.analysisKey,o=sn(r),l=ue[n],a=Ae[n];if(!j(l)&&!j(a))return null;var c=I(o.score,o.relation,o.hasContent,se);return c?i(_,{ref:rn.current[n],label:t,content:l,highlights:o.highlightsA,styleVariant:c,isHighlighted:Fe===r||Fe===n},"left-".concat(n)):null}),We&&_e.map(function(e,n){return{section:e,idx:n}}).filter(function(e){var n=e.section;return j(n.title)||j(n.content)||(n.subsections||[]).some(j)}).map(function(n){var t=n.section,r=n.idx;return i(u,e({ref:Oe(r)},{children:hn(t,r,"left",ln.current[r]||o.createRef())}),"left-row-".concat(r))})]}))]})),i(u,e({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"6px",gap:0}},{children:i(u,e({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:t(u,e({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:[i(u,e({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:i(D,{})})),je,"% Similarity",i(E,{size:11})]}))}))})),t(u,e({sx:{border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0}},{children:[i(u,e({ref:Ke,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"24px",display:"flex",alignItems:"center"}},{children:i(p,e({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",display:"flex",alignItems:"center",gap:1}},{children:Ie}))})),t(u,e({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[tn.map(function(e){var n=e.key,t=e.label,r=e.analysisKey,o=sn(r),l=ue[n],a=Ae[n];if(!j(l)&&!j(a))return null;var c=I(o.score,o.relation,o.hasContent,se);return c?i(_,{ref:on.current[n],label:t,content:a,highlights:o.highlightsB,styleVariant:c,isHighlighted:Fe===r||Fe===n},"right-".concat(n)):null}),We&&ze.map(function(e,n){return{section:e,idx:n}}).filter(function(e){var n=e.section;return j(n.title)||j(n.content)||(n.subsections||[]).some(j)}).map(function(e){var n=e.section,t=e.idx;return hn(n,t,"right",an.current[t]||o.createRef())})]}))]}))]}))}))}))]}))};export{H as DEFAULT_COMPARISON_CONFIG,L as DEFAULT_FIELD_CONFIG,O as default};
1
+ import{__assign as e,__spreadArray as n}from"tslib";import{jsxs as i,jsx as t,Fragment as r}from"react/jsx-runtime";import o,{useState as l,useMemo as a,useRef as c,useEffect as s,useCallback as d}from"react";import{Box as u,Typography as p,Skeleton as h,Snackbar as x,Alert as g,IconButton as f,Accordion as v,AccordionSummary as m,AccordionDetails as b}from"@mui/material";import{ChevronDown as y,ArrowLeft as F,ArrowRight as w,ChevronUp as E,X as C}from"lucide-react";import S from"react-dom";import D from"../../assests/svg/SparkleIcon.js";import{ButtonCognitiveIcon as B}from"../../assests/svg/ButtonCognitiveIcon.js";import k from"react-markdown";var A=function(e){return null==e?"":"string"==typeof e?e:Array.isArray(e)?e.map(A).join("\n\n"):"object"==typeof e?JSON.stringify(e):String(e)},R={fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,wordBreak:"break-word",overflowWrap:"break-word",overflow:"hidden","& p":{mt:0,mb:1.5},"& p:last-child":{mb:0},"& ul, & ol":{mt:0,mb:1.5,pl:2.5},"& li":{mb:.5},"& strong":{fontWeight:600},"& code":{whiteSpace:"pre-wrap",wordBreak:"break-word"}},_=function(e){return e?A(e).replace(/\\n/g,"\n").split(/(\*\*.*?\*\*)/g).map(function(e,n){return e.startsWith("**")&&e.endsWith("**")?t("strong",{children:e.slice(2,-2)},n):t(o.Fragment,{children:e},n)}):null},I=function(n,i,t,r){var o=100*(n||0),l=r.thresholds,a=r.relationStyles;if(!t)return null;var c=function(e){return e&&"string"==typeof e?e.split("_").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}).join(" "):"Unknown"}(i),s=(i||"").toLowerCase();return s.includes("no_deviation")?e(e({},a.low),{label:c}):s.includes("deviation")||s.includes("high_risk")||s.includes("critical")?e(e({},a.high),{label:c}):o>=l.exact?e(e({},a.exact),{label:c}):o>=l.high?e(e({},a.high),{label:c}):o>=l.medium?e(e({},a.medium),{label:c}):e(e({},a.low),{label:c})},z=function(n,i,r){if(!n)return null;if(!i||0===i.length)return _(n);var l=i.filter(function(e){return e&&"string"==typeof e&&e.length>0}).map(function(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")});if(0===l.length)return _(n);var a=new RegExp("(".concat(l.join("|"),")"),"gi");return n.split(a).map(function(n,l){return i.some(function(e){return e&&"string"==typeof e&&e.toLowerCase()===n.toLowerCase()})?t(u,e({component:"span",sx:{bgcolor:r.highlightBg,borderRadius:"2px",px:"2px"}},{children:_(n)}),l):t(o.Fragment,{children:_(n)},l)})},W=o.memo(o.forwardRef(function(n,r){var o=n.label,l=n.content,a=n.highlights,c=void 0===a?[]:a,s=n.styleVariant,d=n.isHighlighted,h=void 0!==d&&d,x=Array.isArray(l)?l.map(A).join("\n"):A(l),g=function(e){return"#9F1239"===e.badgeText?{borderColor:"#E11D48",shadow:"rgba(225, 29, 72, 0.25)"}:"#B91C1C"===e.badgeText?{borderColor:"#EF4444",shadow:"rgba(239, 68, 68, 0.25)"}:"#1D4ED8"===e.badgeText?{borderColor:"#3B82F6",shadow:"rgba(59, 130, 246, 0.25)"}:"#A16207"===e.badgeText?{borderColor:"#F59E0B",shadow:"rgba(245, 158, 11, 0.25)"}:{borderColor:"#6366F1",shadow:"rgba(99, 102, 241, 0.25)"}}(s);return i(u,e({sx:{mb:1.5}},{children:[t(p,e({sx:{fontSize:"12px",color:"#19213D",mb:.5,fontWeight:500}},{children:o})),t(u,e({ref:r,sx:{p:"4px 12px",borderRadius:"6px",border:h?"1.5px solid ".concat(g.borderColor):"1px solid ".concat(s.border),boxShadow:h?"0px 0px 0px 2px ".concat(g.shadow):"none",bgcolor:s.bg,fontSize:"13px",color:"#0B0E1A",lineHeight:1.4,minHeight:"24px",display:"flex",alignItems:"center",whiteSpace:"pre-line",wordBreak:"break-word"}},{children:t(u,{children:z(x,c,s)})}))]}))})),T=12,L=10,H=function(n){var o,c,d,h,x,g=n.open,v=n.onClose,m=n.sectionTitle,b=n.referenceSectionTitle,y=n.cognitiveData,F=n.relevanceScore,w=n.anchorEl,E=n.badgeStyle,B=n.popupRef,A=n.position,_=l("association"),I=_[0],z=_[1],W=a(function(){if(!E)return{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"};var e=E.badgeText;return"#9F1239"===e||"#B42318"===e?{border:"#E11D48",shadow:"rgba(225,29,72,0.15)"}:"#1D4ED8"===e?{border:"#3B82F6",shadow:"rgba(59,130,246,0.15)"}:"#A16207"===e?{border:"#F59E0B",shadow:"rgba(245,158,11,0.15)"}:{border:"#5928ED",shadow:"rgba(89,40,237,0.18)"}},[E]);if(s(function(){if(g){var e=function(e){var n;(null===(n=B.current)||void 0===n?void 0:n.contains(e.target))||(null==w?void 0:w.contains(e.target))||v()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[g,v,w,B]),!g||!y)return null;var T=null!==(c=null!==(o=y.relevance_score)&&void 0!==o?o:F)&&void 0!==c?c:0,H=y.decisioning,j=Array.isArray(H)?H:"string"==typeof H&&H.trim()?[H]:[],M=y.gap,O=Array.isArray(M)?M:"string"==typeof M&&M.trim()?[M]:[],P=null!==(d=null==A?void 0:A.arrowLeft)&&void 0!==d?d:60,V=i(u,e({ref:B,sx:{position:"fixed",top:null!==(h=null==A?void 0:A.top)&&void 0!==h?h:-9999,left:null!==(x=null==A?void 0:A.left)&&void 0!==x?x:-9999,zIndex:9999,width:"min(".concat(680,"px, calc(100vw - ").concat(24,"px))"),bgcolor:"#FFFFFF",borderRadius:"14px",border:"1.5px solid ".concat(W.border),boxShadow:"0px 8px 32px ".concat(W.shadow,", 0px 0px 0px 3px ").concat(W.shadow),overflow:"visible",display:"flex",flexDirection:"column",maxHeight:(null==A?void 0:A.maxHeight)?"min(60vh, ".concat(A.maxHeight,"px)"):"60vh",visibility:A?"visible":"hidden"}},{children:[A&&(A.openAbove?i(r,{children:[t(u,{sx:{position:"absolute",bottom:-11,left:P-L,width:0,height:0,borderLeft:"".concat(L,"px solid transparent"),borderRight:"".concat(L,"px solid transparent"),borderTop:"".concat(11,"px solid ").concat(W.border),zIndex:1}}),t(u,{sx:{position:"absolute",bottom:-9,left:P-L+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderTop:"".concat(L,"px solid #FFFFFF"),zIndex:2}})]}):i(r,{children:[t(u,{sx:{position:"absolute",top:-11,left:P-L,width:0,height:0,borderLeft:"".concat(L,"px solid transparent"),borderRight:"".concat(L,"px solid transparent"),borderBottom:"".concat(11,"px solid ").concat(W.border),zIndex:1}}),t(u,{sx:{position:"absolute",top:-9,left:P-L+1,width:0,height:0,borderLeft:"".concat(9,"px solid transparent"),borderRight:"".concat(9,"px solid transparent"),borderBottom:"".concat(L,"px solid #FFFFFF"),zIndex:2}})]})),i(u,e({sx:{px:2.5,pt:2,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0}},{children:[i(u,e({sx:{flex:1,minWidth:0}},{children:[i(p,e({sx:{fontSize:"18px",fontWeight:600,color:"#101828",lineHeight:1.3,display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap",overflow:"hidden"}},{children:[t(u,e({component:"span",title:m,sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:m})),t(u,e({component:"span",sx:{color:"#667085",fontWeight:400,flexShrink:0,mx:.5}},{children:"↔"})),t(u,e({component:"span",title:b||"Reference Section",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flexShrink:1,minWidth:0}},{children:b||"Reference Section"}))]})),t(u,e({sx:{mt:.75,display:"inline-flex",alignItems:"center",gap:.75}},{children:t(p,e({sx:{fontSize:"13px",fontWeight:400,color:"#5928ED",lineHeight:1}},{children:"deviation"===I?"Why this is a deviation?":"Why these sections are paired?"}))}))]})),i(u,e({sx:{display:"flex",alignItems:"center",gap:1.5,flexShrink:0}},{children:[i(u,e({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:[t(D,{}),"Decision Strength ",T,"%"]})),t(f,e({onClick:v,size:"small",sx:{color:"#667085",width:24,height:24,"&:hover":{bgcolor:"transparent",color:"#101828"}}},{children:t(C,{size:22})}))]}))]})),t(u,e({sx:{display:"flex",borderBottom:"1px solid #E4E7EC",px:2.5,flexShrink:0}},{children:["deviation","association"].map(function(n){var i=I===n;return t(u,e({onClick:function(){return z(n)},sx:{pb:"10px",pt:"4px",mr:3,px:2,cursor:"pointer",fontSize:"14px",fontWeight:i?600:400,color:i?"#5928ED":"#667085",backgroundColor:i?"rgba(89,40,237,0.08)":"transparent",borderBottom:i?"2px solid #5928ED":"2px solid transparent",transition:"all 0.15s",userSelect:"none",overflowY:"auto"}},{children:"deviation"===n?"Deviation Analysis":"Association Logic"}),n)})})),t(u,e({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(W.border,"55"),borderRadius:"10px"},"&::-webkit-scrollbar-thumb:hover":{background:W.border},scrollbarWidth:"thin",scrollbarColor:"".concat(W.border,"55 transparent")}},{children:"deviation"===I?i(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD",p:2,display:"flex",flexDirection:"column",gap:1}},{children:[t(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054"}},{children:"Deviation Analysis"})),t(p,e({sx:{fontSize:"14px",color:"#667085",lineHeight:1.6}},{children:"Deviation analysis content will appear here. This tab shows structural and semantic deviations identified between the two sections being compared."}))]})):i(r,{children:[j.length>0&&i(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[t(u,e({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:t(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Decision Making Factors"}))})),t(u,e({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:t(u,e({sx:{display:"flex",flexDirection:"column"}},{children:t(p,e({component:"div",sx:e({},R)},{children:t(k,{children:j.join("\n\n")})}))}))}))]})),O.length>0&&i(u,e({sx:{borderRadius:"8px",border:"1px solid #E4E7EC",bgcolor:"#FCFCFD"}},{children:[t(u,e({sx:{px:1.5,py:.75,borderBottom:"1px solid #EAECF0"}},{children:t(p,e({sx:{fontSize:"15px",fontWeight:600,color:"#344054",lineHeight:1.25}},{children:"Gaps in Decision"}))})),t(u,e({sx:{px:1.5,py:1.1,display:"flex",flexDirection:"column",gap:.95}},{children:t(u,e({sx:{display:"flex",flexDirection:"column"}},{children:t(p,e({component:"div",sx:e({},R)},{children:t(k,{children:O.join("\n\n")})}))}))}))]})),0===j.length&&0===O.length&&t(u,e({sx:{p:2,bgcolor:"#F8FAFC",borderRadius:"8px",border:"1px solid #E2E8F0"}},{children:t(p,e({sx:{fontSize:"13px",color:"#64748B"}},{children:"No cognitive decisioning data available for this section."}))}))]})}))]}));return S.createPortal(V,document.body)},j=o.memo(function(n){var r=n.data,o=n.isSelected,l=n.isCognitiveOpen,a=n.onToggleCognitive,c=n.onClick,s=A(r.summaryText||r.description),d=s.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),x=d?s.replace(d[0],"").trim():s,g=!!d;return i(u,e({id:"variant-card-".concat(r.id),onClick:c,sx:{minWidth:"280px",maxWidth:"280px",p:2,m:.5,bgcolor:o?"#EFF6FF99":"#FFFFFF",borderRadius:"8px",cursor:"pointer",transition:"all 0.2s",display:"flex",flexDirection:"column",gap:1,flexShrink:0,opacity:r.isLoading?.7:1,border:o?"1.4px solid #2563EB":void 0,boxShadow:o?"none":"0px 2px 4px 0px #19213D14","&:hover":{borderColor:o?"#2563EB":"#CBD5E1",boxShadow:o?"none":"0px 4px 8px 0px #19213D1F"}}},{children:[t(u,e({sx:{display:"flex",alignItems:"center",gap:1.5}},{children:r.isLoading?t(h,{variant:"rounded",width:80,height:20}):i(u,e({sx:{bgcolor:"#FEF2F2",color:"#B91C1C",fontSize:"11px",fontWeight:600,px:1,py:.5,borderRadius:"100px",border:"1px solid #FFE1E1"}},{children:[void 0!==r.similarity?r.similarity:0,"% Similarity"]}))})),i(u,e({sx:{display:"flex",flexDirection:"column",gap:1}},{children:[t(u,e({sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"nowrap"}},{children:t(p,e({sx:{fontWeight:500,fontSize:"14px",color:"#19213D",lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"}},{children:A(r.title)}))})),r.isLoading?i(u,{children:[t(h,{width:"90%"}),t(h,{width:"60%"})]}):i(u,e({sx:{display:"flex",flexDirection:"column",gap:.5}},{children:[t(p,e({sx:{fontWeight:400,fontSize:"13px",color:"#666F8D",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"}},{children:x})),g&&i(u,e({onClick:function(e){e.stopPropagation(),o||c(),a()},sx:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",cursor:"pointer",marginLeft:"-4px","&:hover":{backgroundColor:"#F1F5F9"}}},{children:[t("div",e({style:{width:"13px",height:"13px",display:"flex",alignItems:"center"}},{children:t(B,{})})),t(y,{size:12,style:{transform:o&&l?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}))]}))]}))]}))}),M=[{key:"title",label:"Title",analysisKey:"title"},{key:"description",label:"Description",analysisKey:"description"}],O={fields:M,thresholds:{exact:90,high:70,medium:40},relationStyles:{noContent:{bg:"#FFFFFF",border:"#E2E8F0",badgeBg:"#F8FAFC",badgeBorder:"#F1F5F9",badgeText:"#64748B",highlightBg:"transparent"},exact:{bg:"#FFF1F2",border:"#FECDD3",badgeBg:"#FFE4E6",badgeBorder:"#FEE2E2",badgeText:"#9F1239",highlightBg:"#FECDD3"},high:{bg:"#FFF5F5",border:"#FECACA",badgeBg:"#FEECEC",badgeBorder:"#F8C2C2",badgeText:"#B42318",highlightBg:"#FDD5D5"},medium:{bg:"#FFFCF6",border:"#FFDD80",badgeBg:"#FEF9C3",badgeBorder:"#FEF08A",badgeText:"#A16207",highlightBg:"#FDDEB3"},low:{bg:"#F5F9FF",border:"#CFE0FF",badgeBg:"#EEF4FF",badgeBorder:"#BFD3FF",badgeText:"#1D4ED8",highlightBg:"#DCEAFF"}}},P=function(e){return null!=e&&("string"==typeof e?e.trim().length>0:!Array.isArray(e)||e.length>0&&e.some(function(e){return P(e)}))},V=function(e,n,i){var t,r=i[n],o=null===(t=null==e?void 0:e.comparison_inputs)||void 0===t?void 0:t[r];return{title:A((null==o?void 0:o.title)||""),content:A((null==o?void 0:o.content)||"")}},K=function(n){var i,t,r,o,l=[],a=[],c=n.base_root_id,s=n.input_index_map||{0:"left",1:"right"},d=n[c];if(!d||!1===d.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[]};var u=function(i){var t=n[i];if(t&&!1!==t.display_node){var r=function(e){if(!e.mapping_rationale)return{score:void 0,relation:"not_defined"};var n=e.mapping_rationale,i=!n.decision_strength,t=parseInt(n.decision_strength||"0");return{cognitiveData:{decisioning:n.decisioning_factors||[],gap:n.gaps_in_decision||[],relevance_score:t},score:i?100:t/100,relation:t>=70?"no_deviation":"deviation"}}(t),o=V(t,"0",s),c=V(t,"1",s),d=o.title.trim()||o.content.trim(),p=c.title.trim()||c.content.trim();l.push(e({id:i,title:d?o.title:"",content:d?o.content:"",subsections:[]},d?r:{score:void 0,relation:"not_defined"})),a.push(e({id:i,title:p?c.title:"",content:p?c.content:"",subsections:[]},p?r:{score:void 0,relation:"not_defined"})),t.next&&Object.values(t.next).forEach(u)}};return d.next&&Object.values(d.next).forEach(u),{activeProposed:{title:(null===(t=null===(i=d.comparison_inputs)||void 0===i?void 0:i[s[0]])||void 0===t?void 0:t.title)||"Uploaded Contract",description:d.decision_scope_description||"",sections:l},activeVariants:[{id:"tree-variant-1",title:(null===(o=null===(r=d.comparison_inputs)||void 0===r?void 0:r[s[1]])||void 0===o?void 0:o.title)||"Reference Template",similarity:0,sections:a,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:d.decision_scope_description||""},fields:{}}}}]}},N={id:"",title:""},q=function(r){var h,C,S,D=r.variants,z=void 0===D?[]:D,V=r.treeData,q=r.comparisonConfig,U=r.onSelectVariant,Y=r.targetVariantId,G=r.highlightedField,J=l(null),$=J[0],X=J[1],Q=a(function(){return(null==V?void 0:V.cognitive_decisioning)||{}},[V]),Z=c(null),ee=l(null),ne=ee[0],ie=ee[1],te=c(null),re=l({open:!1,sectionTitle:"",refSectionTitle:"",cognitiveData:null,anchorEl:null,sectionAnchorEl:null,badgeStyle:null,sectionIdx:null}),oe=re[0],le=re[1],ae=c(null),ce=c(null),se=c(null),de=c(!1),ue=c(null);s(function(){ue.current=null},[oe.sectionIdx,oe.open]);var pe=d(function(){var e;if(oe.anchorEl&&oe.refSectionTitle){var n=oe.anchorEl.getBoundingClientRect(),i=(null===(e=null==te?void 0:te.current)||void 0===e?void 0:e.offsetHeight)||0,t=Math.min(680,window.innerWidth-24),r=window.innerHeight-n.bottom-12-T,o=n.top-12-T,l=r<i&&o>r;null!==ue.current?!0===ue.current&&(l=o>=i||o>=r):l=!(r>=i||r>=o),ue.current=l;var a=l?o:r,c=Math.min(i||9999,a),s=l?n.top-12-c:n.bottom+12,d=n.left+n.width/2,u=d-t/2,p=Math.max(T,Math.min(u,window.innerWidth-t-T)),h=Math.max(14,Math.min(d-p,t-L-4));ie({top:s,left:p,arrowLeft:h,openAbove:l,maxHeight:a})}},[oe.anchorEl,oe.refSectionTitle]);s(function(){if(oe.open){window.addEventListener("resize",pe);var e=requestAnimationFrame(pe),n=null;return te.current&&(n=new ResizeObserver(function(){e=requestAnimationFrame(pe)})).observe(te.current),function(){cancelAnimationFrame(e),window.removeEventListener("resize",pe),n&&n.disconnect()}}},[oe.open,pe]),s(function(){var n=ce.current;if(n&&oe.open){var i=function(n){te.current&&te.current.contains(n.target)||(console.log("Scroll event detected on:",n.target,"- closing CognitivePopup"),ie(null),le(function(n){return e(e({},n),{open:!1,anchorEl:null,sectionAnchorEl:null})}))};return n.addEventListener("scroll",i,{capture:!0}),window.addEventListener("scroll",i,{capture:!0}),function(){n.removeEventListener("scroll",i,{capture:!0}),window.removeEventListener("scroll",i,{capture:!0})}}},[oe.open]);var he=a(function(){var n,i,t,r,o,l,a,c,s,d,u,p;return{fields:null!==(n=null==q?void 0:q.fields)&&void 0!==n?n:M,thresholds:{high:null!==(t=null===(i=null==q?void 0:q.thresholds)||void 0===i?void 0:i.high)&&void 0!==t?t:O.thresholds.high,medium:null!==(o=null===(r=null==q?void 0:q.thresholds)||void 0===r?void 0:r.medium)&&void 0!==o?o:O.thresholds.medium,exact:null!==(a=null===(l=null==q?void 0:q.thresholds)||void 0===l?void 0:l.exact)&&void 0!==a?a:O.thresholds.exact},relationStyles:{noContent:e(e({},O.relationStyles.noContent),(null===(c=null==q?void 0:q.relationStyles)||void 0===c?void 0:c.noContent)||{}),high:e(e({},O.relationStyles.high),(null===(s=null==q?void 0:q.relationStyles)||void 0===s?void 0:s.high)||{}),exact:e(e({},O.relationStyles.exact),(null===(d=null==q?void 0:q.relationStyles)||void 0===d?void 0:d.exact)||{}),medium:e(e({},O.relationStyles.medium),(null===(u=null==q?void 0:q.relationStyles)||void 0===u?void 0:u.medium)||{}),low:e(e({},O.relationStyles.low),(null===(p=null==q?void 0:q.relationStyles)||void 0===p?void 0:p.low)||{})}}},[q]),xe=a(function(){if(V&&Object.keys(V).length>0)try{var n=K(V);return e(e({},n),{parseError:null})}catch(e){return console.error("Data Transformation Error: ",e),{activeProposed:{},activeVariants:z||[],parseError:e instanceof Error?e.message:"Unknown Parsing Error"}}return{activeProposed:{},activeVariants:z||[],parseError:null}},[V,z]),ge=xe.activeProposed,fe=xe.activeVariants,ve=xe.parseError;s(function(){ve&&X("Failed to load comparison: ".concat(ve))},[ve]);var me=l(Y||null),be=me[0],ye=me[1],Fe=l(!1),we=Fe[0],Ee=Fe[1],Ce=l(null),Se=Ce[0],De=Ce[1],Be=l({}),ke=Be[0],Ae=Be[1];s(function(){if(Y&&ye(Y),De(null!=G?G:null),G){var e=setTimeout(function(){return De(null)},6e3);return function(){return clearTimeout(e)}}},[Y,G]);var Re=function(e){var n;null===(n=ae.current)||void 0===n||n.scrollBy({left:"left"===e?-300:300,behavior:"smooth"})},_e=a(function(){return n([],fe,!0).sort(function(e,n){return(n.similarity||0)-(e.similarity||0)})},[fe]),Ie=a(function(){if(be){var e=String(be).trim();return fe.find(function(n){return n.id&&String(n.id).trim()===e})||_e[0]}return _e[0]||null},[be,fe,_e]);s(function(){be&&ae.current&&setTimeout(function(){var e=document.getElementById("variant-card-".concat(be.trim())),n=ae.current;if(e&&n){var i=e.offsetLeft-n.offsetLeft-n.clientWidth/2+e.clientWidth/2;n.scrollTo({left:i,behavior:"smooth"})}},150)},[be,_e]);var ze=Ie||N,We=A(ge.title)||"Uploaded Contract",Te=A(ze.title)||"Reference Template",Le=a(function(){return ge.sections||[]},[ge.sections]),He=a(function(){return ze.sections||[]},[ze.sections]),je=Le.length>0||He.length>0,Me=null==Ie?void 0:Ie.analysis,Oe=A(null===(C=null===(h=null==Me?void 0:Me.rule_difference_comparison)||void 0===h?void 0:h.summary)||void 0===C?void 0:C.overall_summary),Pe=!!Oe.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),Ve=null!==(S=null==Ie?void 0:Ie.similarity)&&void 0!==S?S:0,Ke=c({}),Ne=function(e){return Ke.current[e]||(Ke.current[e]=o.createRef()),Ke.current[e]};s(function(){!be&&!Y&&_e.length>0&&!_e[0].isLoading&&ye(_e[0].id)},[_e,be,Y]);var qe=c(null),Ue=c(null),Ye=c(null),Ge=l([]),Je=Ge[0],$e=Ge[1],Xe=l(null),Qe=Xe[0],Ze=Xe[1],en=l(!1),nn=en[0],tn=en[1],rn=l(!1),on=rn[0],ln=rn[1];s(function(){var e=ae.current;if(e){var n=function(){tn(e.scrollLeft>0),ln(e.scrollLeft+e.clientWidth<e.scrollWidth-1)};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),function(){e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}}},[_e]);var an=a(function(){return he.fields.filter(function(e){var n=e.key;return(!je||"description"!==n)&&(P(ge[n])||P(ze[n]))})},[ge,ze,je,he.fields]),cn=c({}),sn=c({}),dn=c({}),un=c({});an.forEach(function(e){var n=e.key;cn.current[n]||(cn.current[n]=o.createRef()),sn.current[n]||(sn.current[n]=o.createRef())});for(var pn=0;pn<Math.max(Le.length,He.length);pn+=1)dn.current[pn]||(dn.current[pn]=o.createRef()),un.current[pn]||(un.current[pn]=o.createRef());s(function(){if(Se){var e=he.fields.find(function(e){return e.analysisKey===Se||e.key===Se});if(e){var n=cn.current[e.key]||sn.current[e.key];(null==n?void 0:n.current)&&setTimeout(function(){return n.current.scrollIntoView({behavior:"smooth",block:"center"})},150)}}},[Se,he.fields]);var hn=d(function(e){var n,i,t,r,o,l,a,c,s,d=null===(n=null==Me?void 0:Me.rule_difference_comparison)||void 0===n?void 0:n.fields;if(!d||!d[e])return{score:0,relation:"",highlightsA:[],highlightsB:[],hasContent:!1};var u=d[e],p=(null==u?void 0:u.relation)||(null===(t=null===(i=null==u?void 0:u.highlights)||void 0===i?void 0:i.ruleA_spans)||void 0===t?void 0:t.length)||(null===(o=null===(r=null==u?void 0:u.highlights)||void 0===r?void 0:r.ruleB_spans)||void 0===o?void 0:o.length)||(null==u?void 0:u.mappings)&&u.mappings.length>0;if(u.mappings){var h=u.mappings[0]||{};return{score:u.score,relation:h.relation||"",highlightsA:(null===(l=h.highlights)||void 0===l?void 0:l.ruleA_spans)||[],highlightsB:(null===(a=h.highlights)||void 0===a?void 0:a.ruleB_spans)||[],hasContent:!!p}}return{score:u.score,relation:u.relation||"",highlightsA:(null===(c=u.highlights)||void 0===c?void 0:c.ruleA_spans)||[],highlightsB:(null===(s=u.highlights)||void 0===s?void 0:s.ruleB_spans)||[],hasContent:!!p}},[Me]),xn=d(function(n){var i,t,r=Le[n],o=He[n],l=(null==r?void 0:r.relation)&&"not_defined"!==r.relation,a=(null==o?void 0:o.relation)&&"not_defined"!==o.relation,c=!(!(null==r?void 0:r.cognitiveData)&&!(null==o?void 0:o.cognitiveData));if(!l&&!a&&!c)return e(e({},he.relationStyles.noContent),{label:"Not Defined"});var s,d=hn("description"),u=null!==(i=null==r?void 0:r.cognitiveRelevanceScore)&&void 0!==i?i:null==o?void 0:o.cognitiveRelevanceScore;if(null!=u){var p=(s=u)>=90?{score:1,relation:"exact_match"}:s>=70?{score:.8,relation:"high_match"}:s>=40?{score:.5,relation:"partial_match"}:{score:0,relation:"no_deviation"};return I(p.score,p.relation,!0,he)}var h=l?r.relation:a?o.relation:d.relation,x=null!==(t=null==r?void 0:r.score)&&void 0!==t?t:null==o?void 0:o.score,g="number"==typeof x?x:d.score;return I(g,h,!0,he)},[Le,He,he,hn]),gn=d(function(){var e,n,i;if(!de.current){de.current=!0;try{if(!qe.current)return;var t=qe.current.getBoundingClientRect(),r=[];an.forEach(function(e){var n=e.key,i=e.analysisKey,o=cn.current[n],l=sn.current[n];if((null==o?void 0:o.current)&&(null==l?void 0:l.current)){o.current.style.height="auto",l.current.style.height="auto",o.current.style.minHeight="0px",l.current.style.minHeight="0px";var a=o.current.getBoundingClientRect().height,c=l.current.getBoundingClientRect().height,s=Math.max(a,c);o.current.style.minHeight="".concat(s,"px"),l.current.style.minHeight="".concat(s,"px");var d=o.current.getBoundingClientRect(),u=l.current.getBoundingClientRect(),p=hn(i),h=I(p.score,p.relation,p.hasContent,he);if(!h)return;var x=d.top+d.height/2-t.top;r.push({id:"field-".concat(n),x1:d.right-t.left,y1:x,x2:u.left-t.left,y2:x,style:h})}});for(var o=Math.min(Le.length,He.length),l=0;l<o;l+=1){var a=dn.current[l],c=un.current[l];if((null==a?void 0:a.current)&&(null==c?void 0:c.current)){a.current.style.height="auto",c.current.style.height="auto",a.current.style.minHeight="0px",c.current.style.minHeight="0px";var s=Math.max(a.current.getBoundingClientRect().height,c.current.getBoundingClientRect().height);a.current.style.minHeight="".concat(s,"px"),c.current.style.minHeight="".concat(s,"px");var d=a.current.querySelector(".MuiAccordionSummary-root"),u=c.current.querySelector(".MuiAccordionSummary-root");if(d&&u){var p=d.getBoundingClientRect(),h=u.getBoundingClientRect(),x=(p.top+p.height/2-t.top+h.top+h.height/2-t.top)/2,g=(null===(e=He[l])||void 0===e?void 0:e.id)||"sec-".concat(l),f=xn(l);f&&r.push({id:g,x1:p.right-t.left,y1:x,x2:h.left-t.left,y2:x,style:f,sectionIdx:l,hasCognitive:!(!(null===(n=Le[l])||void 0===n?void 0:n.cognitiveData)&&!(null===(i=He[l])||void 0===i?void 0:i.cognitiveData))})}}}if($e(r),Ue.current&&Ye.current){var v=Ue.current.getBoundingClientRect(),m=Ye.current.getBoundingClientRect(),b=(v.top+v.height/2-t.top+m.top+m.height/2-t.top)/2;Ze({x1:v.right-t.left,x2:m.left-t.left,y:b})}else Ze(null)}catch(e){console.error("Line render safe fail: ",e)}finally{de.current=!1}}},[an,Le,He,he,hn,xn]);s(function(){var e=setTimeout(gn,250);window.addEventListener("resize",gn);var n=null;return ce.current&&(n=new ResizeObserver(function(){return window.requestAnimationFrame(gn)})).observe(ce.current),function(){clearTimeout(e),window.removeEventListener("resize",gn),null==n||n.disconnect()}},[ge,ze,Me,we,an,ke,Le,He,he,gn]);var fn=function(n,r,o,l){var a=!P(n.title)&&!P(n.content);return t(u,e({ref:l,sx:{mb:1,minHeight:0,display:"flex",flexDirection:"column"}},{children:i(v,e({disableGutters:!0,expanded:!a&&!!ke[r],onChange:function(){return!a&&(n=r,void Ae(function(i){var t;return e(e({},i),((t={})[n]=!i[n],t))}));var n},sx:{boxShadow:"none",border:a?"1px dashed #E2E8F0":"1px solid #E2E8F0",bgcolor:a?"#FAFAFA":"#FFFFFF",borderRadius:"6px",flex:1,display:"flex",flexDirection:"column","&:before":{display:"none"}}},{children:[t(m,e({expandIcon:a?null:t(y,{size:16}),sx:{minHeight:"36px",flexShrink:0,cursor:a?"default":"pointer","& .MuiAccordionSummary-content":{my:.5,display:"flex",alignItems:"center",overflow:"hidden"},"& .MuiAccordionSummary-expandIconWrapper":{transition:"transform 0.2s ease"},"& .MuiAccordionSummary-expandIconWrapper.Mui-expanded":{transform:"rotate(180deg)"}}},{children:t(p,e({sx:{fontSize:"12px",color:a?"#94A3B8":"#19213D",fontWeight:a?400:700,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},{children:_(n.title||"No Matching Section Found")}))})),!a&&i(b,e({sx:{pt:0,pb:1.25,bgcolor:"#FFFFFF",flex:1,display:"flex",flexDirection:"column"}},{children:[t(p,e({component:"div",sx:R},{children:t(k,{children:A(n.content).replace(/\\n/g,"\n")})})),(n.subsections||[]).map(function(n,i){return t(u,e({sx:{mt:1,pt:1,borderTop:"1px solid #EEF2F7"}},{children:t(p,e({component:"div",sx:R},{children:t(k,{children:A(n).replace(/\\n/g,"\n")})}))}),"".concat(o,"-sub-").concat(r,"-").concat(i))})]}))]}))}),"".concat(o,"-sec-").concat(r))};return i(u,e({ref:se,sx:{display:"flex",flexDirection:"column",height:"100%",bgcolor:"#F6F7F9B2",fontFamily:'"Plus Jakarta Sans", sans-serif',overflow:"visible",position:"relative"}},{children:[oe.open&&t(H,{open:oe.open,popupRef:te,position:ne,onClose:function(){ie(null),le(function(n){return e(e({},n),{open:!1})})},sectionTitle:oe.sectionTitle,referenceSectionTitle:oe.refSectionTitle,cognitiveData:oe.cognitiveData,anchorEl:oe.anchorEl,sectionAnchorEl:oe.sectionAnchorEl,scrollContainerEl:ce.current,badgeStyle:oe.badgeStyle}),t(x,e({open:!!$,autoHideDuration:8e3,onClose:function(){return X(null)},anchorOrigin:{vertical:"top",horizontal:"center"}},{children:t(g,e({onClose:function(){return X(null)},severity:"error",sx:{width:"100%",whiteSpace:"pre-line"}},{children:$}))})),_e.length>1&&i(u,e({sx:{px:3,pb:.25},ref:Z},{children:[i(u,e({sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1}},{children:[t(p,e({sx:{fontSize:"13px",color:"#475569"}},{children:"Choose the Learning you want to compare with the rule you are creating."})),i(u,e({sx:{display:"flex",gap:.5,flexShrink:0,ml:1}},{children:[t(f,e({onClick:function(){return Re("left")},size:"small",disabled:!nn},{children:t(F,{size:18})})),t(f,e({onClick:function(){return Re("right")},size:"small",disabled:!on},{children:t(w,{size:18})}))]}))]})),t(u,e({ref:ae,sx:{display:"flex",gap:1,overflowX:"auto",pb:.05,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"transparent",borderRadius:"10px"}}},{children:_e.map(function(e){return t(j,{data:e,isSelected:(null==Ie?void 0:Ie.id)===e.id,isCognitiveOpen:we,onToggleCognitive:function(){return Ee(function(e){return!e})},onClick:function(){return ye((n=e).id),U(n),void Ee(!1);var n}},e.id)})}))]})),t(u,e({ref:ce,sx:{flex:1,overflowY:"auto",minHeight:0,pt:1.5,pb:8,px:3,display:"flex",justifyContent:"center",alignItems:"flex-start",bgcolor:"#FFFFFF",borderTop:Oe&&Pe&&we?"none":"1.5px solid #EEF0F4"}},{children:t(u,e({sx:{display:"flex",flexDirection:"column",width:"100%",maxWidth:"1200px"}},{children:i(u,e({ref:qe,sx:{display:"grid",gridTemplateColumns:"1fr auto 1fr",gap:"60px",maxWidth:"1200px",width:"100%",position:"relative"}},{children:[i("svg",e({style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10}},{children:[Qe&&i("g",{children:[t("line",{x1:Qe.x1,y1:Qe.y,x2:Math.max(Qe.x1,(Qe.x1+Qe.x2)/2-70),y2:Qe.y,stroke:"#BBF7D0",strokeWidth:"1.5"}),t("line",{x1:Math.min(Qe.x2,(Qe.x1+Qe.x2)/2+70),y1:Qe.y,x2:Qe.x2,y2:Qe.y,stroke:"#BBF7D0",strokeWidth:"1.5"})]}),Je.map(function(n,r){var o=(n.x1+n.x2)/2;return"Not Defined"!==n.style.label||n.hasCognitive?i("g",{children:[t("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,stroke:n.style.badgeBorder,strokeWidth:"1.5"}),t("foreignObject",e({x:o-75,y:n.y1-14,width:"150",height:"28",style:{pointerEvents:"auto",overflow:"visible"}},{children:t(u,e({sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"}},{children:i(u,e({sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"11px",bgcolor:n.style.badgeBg,color:n.style.badgeText,border:"1px solid ".concat(n.style.badgeBorder),borderRadius:"12px",px:1.5,py:.5,fontWeight:500,textAlign:"center",whiteSpace:"nowrap",cursor:"pointer"}},{children:[n.style.label,i(u,e({onClick:function(i){if(i.stopPropagation(),oe.open&&oe.sectionIdx===n.sectionIdx)return ie(null),void le(function(n){return e(e({},n),{open:!1})});!function(e,n,i,t,r){var o,l;e.stopPropagation(),ie(null);var a=A(n.id)||A(i.id)||"",c=(a?Q[a]:null)||n.cognitiveData||i.cognitiveData||null,s=null!==(l=null===(o=Ke.current[t])||void 0===o?void 0:o.current)&&void 0!==l?l:null;le({open:!0,sectionTitle:n.title||"Section",refSectionTitle:i.title||"Reference Section",cognitiveData:c,anchorEl:e.currentTarget,sectionAnchorEl:s,badgeStyle:r||null,sectionIdx:t})}(i,Le[n.sectionIdx]||{title:"",content:""},He[n.sectionIdx]||{title:"",content:""},n.sectionIdx,n.style)}},{children:[n.hasCognitive&&void 0!==n.sectionIdx&&t(u,e({sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"4px",px:"4px",ml:"2px",color:n.style.badgeText,transition:"background 0.15s"}},{children:t("div",e({style:{width:"13px",height:"13px",display:"flex",alignItems:"center",marginRight:"2px"}},{children:t(B,{})}))})),oe.open&&oe.sectionIdx===n.sectionIdx?t(E,{size:12,color:n.style.badgeText}):t(y,{size:12,color:n.style.badgeText})]}))]}))}))}))]},r):null})]})),i(u,e({sx:{border:"1px dashed #B0B0B0",borderRadius:"8px",bgcolor:"#FFFFFF",display:"flex",flexDirection:"column",position:"relative",zIndex:2,filter:"drop-shadow(0px 2px 4px #F2F2F2)",minWidth:0}},{children:[t(u,e({ref:Ue,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px dashed #B0B0B0",borderRadius:"8px 8px 0 0",display:"flex",minHeight:"24px",alignItems:"center"}},{children:t(p,e({sx:{fontSize:"16px",fontWeight:500,color:"#19213D"}},{children:We}))})),i(u,e({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[an.map(function(e){var n=e.key,i=e.label,r=e.analysisKey,o=hn(r),l=ge[n],a=ze[n];if(!P(l)&&!P(a))return null;var c=I(o.score,o.relation,o.hasContent,he);return c?t(W,{ref:cn.current[n],label:i,content:l,highlights:o.highlightsA,styleVariant:c,isHighlighted:Se===r||Se===n},"left-".concat(n)):null}),je&&Le.map(function(e,n){return{section:e,idx:n}}).map(function(n){var i=n.section,r=n.idx;return t(u,e({ref:Ne(r)},{children:fn(i,r,"left",dn.current[r]||o.createRef())}),"left-row-".concat(r))})]}))]})),t(u,e({sx:{width:"180px",display:"flex",flexDirection:"column",alignItems:"center",pt:"6px",gap:0}},{children:t(u,e({sx:{display:"flex",justifyContent:"center",alignItems:"center",mt:0}},{children:i(u,e({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:[t(u,e({component:"span",sx:{width:14,height:14,display:"flex",alignItems:"center","& svg":{width:"14px",height:"14px"}}},{children:t(B,{})})),Ve,"% Similarity",t(y,{size:11})]}))}))})),i(u,e({sx:{border:"1px solid #E3E6EA",borderRadius:"8px",bgcolor:"#FFFFFF",boxShadow:"0px 1px 4px #F7F4FE",position:"relative",zIndex:2,display:"flex",flexDirection:"column",minWidth:0}},{children:[t(u,e({ref:Ye,sx:{p:"8px",bgcolor:"#F7F8FA",borderBottom:"1px solid #E3E6EA",borderRadius:"8px 8px 0 0",minHeight:"24px",display:"flex",alignItems:"center"}},{children:t(p,e({sx:{fontSize:"16px",fontWeight:500,color:"#5928ED",display:"flex",alignItems:"center",gap:1}},{children:Te}))})),i(u,e({sx:{p:"12px",display:"flex",flexDirection:"column"}},{children:[an.map(function(e){var n=e.key,i=e.label,r=e.analysisKey,o=hn(r),l=ge[n],a=ze[n];if(!P(l)&&!P(a))return null;var c=I(o.score,o.relation,o.hasContent,he);return c?t(W,{ref:sn.current[n],label:i,content:a,highlights:o.highlightsB,styleVariant:c,isHighlighted:Se===r||Se===n},"right-".concat(n)):null}),je&&He.map(function(e,n){return{section:e,idx:n}}).map(function(e){var n=e.section,i=e.idx;return fn(n,i,"right",un.current[i]||o.createRef())})]}))]}))]}))}))}))]}))};export{O as DEFAULT_COMPARISON_CONFIG,M as DEFAULT_FIELD_CONFIG,q as default};
2
2
  //# sourceMappingURL=CognitiveCompare.js.map
@@ -0,0 +1,3 @@
1
+ declare const CognitiveCompareTest: () => import("react/jsx-runtime").JSX.Element;
2
+ export default CognitiveCompareTest;
3
+ //# sourceMappingURL=CognitiveCompareTest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitiveCompareTest.d.ts","sourceRoot":"","sources":["../../../src/CognitiveCompareTest.tsx"],"names":[],"mappings":"AAmsFA,QAAA,MAAM,oBAAoB,+CAazB,CAAA;AAED,eAAe,oBAAoB,CAAA"}
@@ -22,8 +22,8 @@ interface ComparisonAnalysis {
22
22
  }
23
23
  interface CognitiveDecisioningEntry {
24
24
  section_id: string;
25
- decisioning: string;
26
- gap: string;
25
+ decisioning?: string | string[];
26
+ gap?: string | string[];
27
27
  relevance_score: number;
28
28
  metadata?: unknown;
29
29
  decisioning_metadata?: unknown;
@@ -104,6 +104,6 @@ export type ComparisonConfig = {
104
104
  };
105
105
  export declare const DEFAULT_FIELD_CONFIG: FieldConfigItem[];
106
106
  export declare const DEFAULT_COMPARISON_CONFIG: ComparisonConfig;
107
- declare const CognitiveCompare: ({ variants, treeData, comparisonConfig, onSelectVariant, onSkip, onBack, targetVariantId, highlightedField, onBadgeClick, activeBadgeId, }: CognitiveCompareProps) => import("react/jsx-runtime").JSX.Element;
107
+ declare const CognitiveCompare: ({ variants, treeData, comparisonConfig, onSelectVariant, targetVariantId, highlightedField, }: CognitiveCompareProps) => import("react/jsx-runtime").JSX.Element;
108
108
  export default CognitiveCompare;
109
109
  //# sourceMappingURL=CognitiveCompare.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CognitiveCompare.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/CognitiveCompare.tsx"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"CognitiveCompare.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/CognitiveCompare.tsx"],"names":[],"mappings":"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"}
@@ -0,0 +1,141 @@
1
+ /// <reference types="react" />
2
+ export interface ComparisonFieldAnalysis {
3
+ relation: string;
4
+ score: number;
5
+ highlights?: {
6
+ ruleA_spans?: string[];
7
+ ruleB_spans?: string[];
8
+ };
9
+ }
10
+ export interface ComparisonAnalysis {
11
+ rule_difference_comparison: {
12
+ summary: {
13
+ overall_score: number;
14
+ overall_summary: string;
15
+ };
16
+ fields: {
17
+ [key: string]: ComparisonFieldAnalysis | {
18
+ score: number;
19
+ mappings: Record<string, unknown>[];
20
+ };
21
+ };
22
+ };
23
+ }
24
+ export interface CognitiveDecisioningEntry {
25
+ section_id: string;
26
+ decisioning?: string | string[];
27
+ gap?: string | string[];
28
+ relevance_score: number;
29
+ metadata?: unknown;
30
+ decisioning_metadata?: unknown;
31
+ gap_metadata?: unknown;
32
+ }
33
+ export interface RuleData {
34
+ id: string;
35
+ title: string;
36
+ scope?: string;
37
+ description?: string;
38
+ wta?: string;
39
+ wnta?: string;
40
+ [key: string]: unknown;
41
+ similarity?: number;
42
+ summaryText?: string;
43
+ variantType?: string;
44
+ tierName?: string;
45
+ analysis?: ComparisonAnalysis;
46
+ isLoading?: boolean;
47
+ sections?: {
48
+ id?: string;
49
+ title: string;
50
+ content: string;
51
+ subsections?: string[];
52
+ relation?: string;
53
+ score?: number;
54
+ cognitiveRelevanceScore?: number;
55
+ cognitiveData?: CognitiveDecisioningEntry;
56
+ }[];
57
+ }
58
+ export type ProposedRuleData = {
59
+ title?: string;
60
+ description?: string;
61
+ sections?: Record<string, unknown>[];
62
+ };
63
+ export interface CognitiveCompareProps {
64
+ variants?: RuleData[];
65
+ treeData?: Record<string, any> | null;
66
+ comparisonConfig?: Partial<ComparisonConfig>;
67
+ fieldConfig?: {
68
+ key: string;
69
+ label: string;
70
+ analysisKey: string;
71
+ }[];
72
+ onSelectVariant: (variant: RuleData) => void;
73
+ onAddAsVariant?: () => void;
74
+ onSkip?: () => void;
75
+ onBack?: () => void;
76
+ targetVariantId?: string | null;
77
+ highlightedField?: string | null;
78
+ onBadgeClick?: (id: string, isOpen: boolean) => void;
79
+ activeBadgeId?: string | null;
80
+ }
81
+ export type StyleVariant = {
82
+ bg: string;
83
+ border: string;
84
+ badgeBg: string;
85
+ badgeBorder: string;
86
+ badgeText: string;
87
+ highlightBg: string;
88
+ label: string;
89
+ };
90
+ export type FieldConfigItem = {
91
+ key: string;
92
+ label: string;
93
+ analysisKey: string;
94
+ };
95
+ export type RelationStyleToken = Omit<StyleVariant, "label">;
96
+ export type ComparisonConfig = {
97
+ fields: FieldConfigItem[];
98
+ thresholds: {
99
+ exact: number;
100
+ high: number;
101
+ medium: number;
102
+ };
103
+ relationStyles: {
104
+ noContent: RelationStyleToken;
105
+ high: RelationStyleToken;
106
+ exact: RelationStyleToken;
107
+ medium: RelationStyleToken;
108
+ low: RelationStyleToken;
109
+ };
110
+ };
111
+ export interface FieldProps {
112
+ label: string;
113
+ content: unknown | unknown[];
114
+ highlights?: string[];
115
+ styleVariant: StyleVariant;
116
+ isHighlighted?: boolean;
117
+ }
118
+ export interface PopupPosition {
119
+ top: number;
120
+ left: number;
121
+ arrowLeft: number;
122
+ openAbove: boolean;
123
+ maxHeight: number;
124
+ }
125
+ export interface CognitivePopupProps {
126
+ open: boolean;
127
+ onClose: () => void;
128
+ sectionTitle: string;
129
+ referenceSectionTitle: string;
130
+ cognitiveData: CognitiveDecisioningEntry | null;
131
+ relevanceScore?: number;
132
+ anchorEl: HTMLElement | null;
133
+ sectionAnchorEl: HTMLElement | null;
134
+ scrollContainerEl: HTMLElement | null;
135
+ containerEl?: HTMLElement | null;
136
+ badgeStyle?: StyleVariant | null;
137
+ baseLayoutRef?: any;
138
+ popupRef: React.RefObject<HTMLDivElement>;
139
+ position: PopupPosition | null;
140
+ }
141
+ //# sourceMappingURL=CognitiveCompareTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitiveCompareTypes.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/CognitiveCompareTypes.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,59 @@
1
+ import { ComparisonConfig, FieldConfigItem, StyleVariant } from "./CognitiveCompareTypes";
2
+ export declare const safeStringify: (val: unknown) => string;
3
+ export declare const hasValue: (val: unknown) => boolean;
4
+ export declare const getSideData: (node: any, sideIndex: "0" | "1", indexMap: Record<string, string>) => {
5
+ title: string;
6
+ content: string;
7
+ };
8
+ export declare const getRationale: (node: any) => {
9
+ score: undefined;
10
+ relation: string;
11
+ cognitiveData?: undefined;
12
+ } | {
13
+ cognitiveData: {
14
+ decisioning: any;
15
+ gap: any;
16
+ relevance_score: number;
17
+ };
18
+ score: number;
19
+ relation: string;
20
+ };
21
+ export declare const SHARED_MARKDOWN_STYLES: {
22
+ fontSize: string;
23
+ color: string;
24
+ lineHeight: number;
25
+ wordBreak: string;
26
+ overflowWrap: string;
27
+ overflow: string;
28
+ "& p": {
29
+ mt: number;
30
+ mb: number;
31
+ };
32
+ "& p:last-child": {
33
+ mb: number;
34
+ };
35
+ "& ul, & ol": {
36
+ mt: number;
37
+ mb: number;
38
+ pl: number;
39
+ };
40
+ "& li": {
41
+ mb: number;
42
+ };
43
+ "& strong": {
44
+ fontWeight: number;
45
+ };
46
+ "& code": {
47
+ whiteSpace: string;
48
+ wordBreak: string;
49
+ };
50
+ };
51
+ export declare const formatRelationToLabel: (relation: string) => string;
52
+ export declare const getStyleForRelation: (score: number, relation: string, hasContent: boolean, config: ComparisonConfig) => StyleVariant | null;
53
+ export declare const cognitiveScoreToRelation: (relevanceScore: number) => {
54
+ score: number;
55
+ relation: string;
56
+ };
57
+ export declare const DEFAULT_FIELD_CONFIG: FieldConfigItem[];
58
+ export declare const DEFAULT_COMPARISON_CONFIG: ComparisonConfig;
59
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE1F,eAAO,MAAM,aAAa,QAAS,OAAO,KAAG,MAM5C,CAAC;AACF,eAAO,MAAM,QAAQ,QAAS,OAAO,KAAG,OAKvC,CAAC;AACF,eAAO,MAAM,WAAW,SAChB,GAAG,aACE,GAAG,GAAG,GAAG,YACV,OAAO,MAAM,EAAE,MAAM,CAAC;;;CAQjC,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,GAAG;;;;;;;;;;;;CAerC,CAAC;AACF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAalC,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAc,MAAM,KAAG,MAMxD,CAAC;AAGF,eAAO,MAAM,mBAAmB,UACvB,MAAM,YACH,MAAM,cACJ,OAAO,UACX,gBAAgB,KACvB,YAAY,GAAG,IA6BjB,CAAC;AAGF,eAAO,MAAM,wBAAwB,mBACnB,MAAM,KACrB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAKnC,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAAe,EAGjD,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,gBA6CvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viswa-test/test-citation",
3
- "version": "0.0.14",
3
+ "version": "0.0.17",
4
4
  "author": "Viswa Koduru",
5
5
  "description": "",
6
6
  "license": "MIT",