(function(y,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react"),require("@mui/material"),require("@mui/icons-material"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","@mui/material","@mui/icons-material","react/jsx-runtime"],l):(y=typeof globalThis<"u"?globalThis:y||self,l(y.RdfEntityViewer={},y.React,y.material,y.iconsMaterial,y.jsxRuntime))})(this,function(y,l,s,L,n){"use strict";const F=(o=>o&&typeof o=="object"&&"default"in o?o:{default:o})(l),S=(...o)=>o.filter(e=>typeof e=="string"&&e.length>0).join(" ");function A(o){const{value:e,smaller:t=!1,bigger:r=!1,onCopy:i,title:c}=o;if(r&&t)throw new Error("CopyButton: cannot be both bigger and smaller");return n.jsx(s.Tooltip,{title:c!=null?c:"Copy",arrow:!0,disableInteractive:!0,children:n.jsx(s.IconButton,{size:"small",sx:{marginRight:"5px"},onClick:a=>{a.stopPropagation(),navigator.clipboard.writeText(e).then(()=>i==null?void 0:i()).catch(console.error)},children:n.jsx(L.ContentCopy,{sx:a=>({color:a.palette.text.secondary,fontSize:t?"12px":r?"24px":"16px"})})})})}function B(o){return n.jsx(A,{...o,title:"Copy IRI"})}const Z=o=>{const{href:e,children:t}=o;return n.jsx(s.Link,{href:e,target:"_blank",rel:"noreferrer",children:t})},G=l.createContext(void 0),w=()=>{const o=l.useContext(G);if(o===void 0)throw new Error("useViewerContext must be used within a ContextProvider");return o},C=(o,e)=>{const{prefixes:t}=o,r=k(o,e);if(r!==void 0)return r;let i;for(const[c,a]of Object.entries(t))e.startsWith(a)&&(i===void 0||i.length`},k=(o,e)=>{const{data:t,labelIRIs:r,locale:i}=o;if(t===void 0)return;const c=t[e];if(c===void 0)return;let a,d;for(const u of r){const p=c[u];if(p!==void 0)for(const b of p){if(b.lang===i.language)return b.value;b.lang===void 0?(d===void 0||d==="en-fallback")&&(a=b,d="no-lang"):b.lang==="en"&&a===void 0&&d===void 0&&(a=b,d="en-fallback")}}return a==null?void 0:a.value},W=o=>{let e=0,t;if(o.length===0)return e;for(let r=0;r!t.includes(c)).length>0}function Q(o,e,t){const r=C(o,e),i=C(o,t);return r.localeCompare(i)}function U(o,e,t){const r=W(e.type)-W(t.type);if(r!==0)return r;const i=C(o,e.value),c=C(o,t.value);return i.localeCompare(c)}function R(o){const{children:e,tableContainerProps:t}=o;return n.jsx(s.TableContainer,{component:s.Paper,...t,className:S("RdfEntityViewer-ObjectContainer","RdfEntityViewer-QualifierContainer",t==null?void 0:t.className),children:n.jsx(s.Table,{size:"small",children:n.jsx(s.TableBody,{children:e})})})}function ee(o){const{object:e}=o;if(e.type!=="bnode")throw new Error("BNodeObject only supports BNodes");const t=w(),[r,i]=l.useState();return l.useEffect(()=>{i(k(t,e.value))},[t,e.value]),n.jsx("span",{style:{whiteSpace:"nowrap"},children:r!=null?r:e.value})}function ne(o){const{object:e}=o;if(e.type!=="uri")throw new Error("IRIObject only supports IRIs");const t=w(),{LinkComponent:r}=t,[i,c]=l.useState(!1);l.useEffect(()=>{const u=new Image;u.onload=()=>c(!0),u.onerror=()=>c(!1),u.src=e.value},[]);const[a,d]=l.useState();return l.useEffect(()=>{d(k(t,e.value))},[t,e.value]),n.jsx("span",{style:{whiteSpace:"nowrap"},children:i?n.jsx(r,{href:e.value,label:a,children:n.jsx("img",{src:e.value,alt:e.value,style:{maxWidth:"200px",maxHeight:"200px"}})}):n.jsxs(n.Fragment,{children:[n.jsx(B,{value:e.value}),n.jsx(r,{href:e.value,label:a,children:C(t,e.value)})]})})}function oe(o){const{object:e}=o;if(e.type!=="literal")throw new Error("LiteralObject only supports literals");const t=s.useTheme().palette.grey[500],r=w();return typeof e.lang=="string"?n.jsxs("span",{children:[e.value,n.jsxs("span",{style:{color:t},children:["@",e.lang]})]}):typeof e.datatype=="string"?n.jsxs("span",{children:[e.value,n.jsxs("span",{style:{color:t},children:["^^",C(r,e.datatype)]})]}):n.jsx(n.Fragment,{children:e.value})}function K(o){const{children:e,tableCellProps:t,tableContainerProps:r}=o;return n.jsx(s.TableContainer,{component:s.Paper,...r,className:S("RdfEntityViewer-ObjectContainer",r==null?void 0:r.className),children:n.jsx(s.Table,{children:n.jsx(s.TableHead,{children:n.jsx(s.TableRow,{children:n.jsx(s.TableCell,{...t,children:e})})})})})}function X(o){const{object:e,noContainer:t=!1}=o,r=l.useMemo(()=>t?F.default.Fragment:K,[t]);return n.jsxs(r,{children:[e.type==="uri"&&n.jsx(ne,{object:e}),e.type==="literal"&&n.jsx(oe,{object:e}),e.type==="bnode"&&n.jsx(ee,{object:e})]})}function te(o){const{object:e}=o,t=w(),{data:r,LinkComponent:i}=t;if(r===void 0)throw new Error("Qualifiers requires data");const c=r[e.value];if(c===void 0)return null;const a=l.useMemo(()=>Object.keys(c).sort((d,u)=>Q(t,d,u)),[c]);return n.jsx(R,{children:a.map(d=>n.jsxs(s.TableRow,{children:[n.jsxs(s.TableCell,{sx:{whiteSpace:"nowrap",maxWidth:"500px",minWidth:"200px"},children:[n.jsx(B,{value:d}),n.jsx(i,{href:d,label:k(t,d),children:C(t,d)})]}),n.jsx(s.TableCell,{children:c[d].sort((u,p)=>U(t,u,p)).map((u,p)=>n.jsx(s.Box,{children:n.jsx(X,{object:u,noContainer:!0})},p))})]},d))})}const J=l.createContext(void 0),re=()=>{const o=l.useContext(J);if(o===void 0)throw new Error("usePredicateContext must be used within a ContextProvider");return o};function se(o){const{onClick:e}=o;return n.jsxs(K,{tableCellProps:{onClick:e,sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:"10px",cursor:"pointer",userSelect:"none"}},children:[n.jsx(L.ExpandMore,{}),"See more"]})}function le(o){const{objects:e}=o,t=w(),{data:r,labelIRIs:i}=t;if(r===void 0)throw new Error("Objects: data is undefined");const{howManyVisibleObjects:c,setHowManyVisibleObjects:a}=re(),d=l.useMemo(()=>e.sort((f,h)=>U(t,f,h)),[e]),u=l.useMemo(()=>{const f=[];return d.forEach(h=>{const x=f.length===0?void 0:f[f.length-1],E=x===void 0,V=x!==void 0&&[x[0].type,h.type].filter(v=>v==="bnode").length===1;E||V?f.push([h]):x.push(h)}),f},[d]),p=l.useMemo(()=>u.map(f=>f.filter(h=>h.type!=="bnode"||r===void 0?!0:r[h.value]!==void 0)).filter(f=>f.length>0),[u,r]),b=l.useMemo(()=>p.flat().length>c,[p,c]),j=l.useMemo(()=>p.flat().slice(0,c),[p,c]);return n.jsxs(n.Fragment,{children:[j.map((f,h)=>m(r,f,i)?n.jsx(te,{object:f},h):n.jsx(X,{object:f},h)),b&&n.jsx(se,{onClick:()=>a(p.flat().length)})]})}const T={container:"_container_181zd_1",line:"_line_181zd_7",btn:"_btn_181zd_13"};function ce(o){const{visible:e=!0,onClick:t}=o;return n.jsxs(s.Box,{className:T.container,sx:{display:e?void 0:"none"},children:[n.jsx(s.Box,{className:T.line,sx:r=>({bgcolor:r.palette.divider})}),n.jsx(s.Paper,{className:T.btn,elevation:1,sx:{boxShadow:"none"},children:n.jsx(s.Tooltip,{title:"Collapse",placement:"left",children:n.jsx(s.IconButton,{onClick:t,sx:{borderRadius:"8px"},children:n.jsx(L.UnfoldLess,{})})})})]})}const I={container:"_container_hl8yz_1",predicate:"_predicate_hl8yz_7",content:"_content_hl8yz_17",sticky:"_sticky_hl8yz_21",objects:"_objects_hl8yz_28"},P=5;function ie(o){const{predicate:e,objects:t}=o,r=w(),{LinkComponent:i}=r,[c,a]=l.useState(P),d=l.useMemo(()=>c>P,[c]),u=()=>{a(P)},p={howManyVisibleObjects:c,setHowManyVisibleObjects:a},[b,j]=l.useState();return l.useEffect(()=>{j(k(r,e))},[r,e]),n.jsx(J.Provider,{value:p,children:n.jsxs(s.Box,{className:I.container,children:[n.jsxs(s.Box,{className:I.predicate,children:[n.jsx(s.Box,{className:I.content,children:n.jsxs(s.Box,{className:I.sticky,children:[n.jsx(B,{value:e}),n.jsx(i,{href:e,label:b,children:C(r,e)})]})}),n.jsx(ce,{visible:d,onClick:u})]}),n.jsx(s.Box,{className:I.objects,children:n.jsx(le,{objects:t})})]})})}function ae(){const o=w(),{data:e,iri:t}=o;if(t===void 0)throw new Error("Body: context is missing information");const r=l.useMemo(()=>e==null?void 0:e[t],[e]),i=l.useMemo(()=>{if(r!==void 0)return Object.entries(r).sort(([c],[a])=>Q(o,c,a))},[r]);return i===void 0?n.jsx(s.Box,{sx:{display:"flex",justifyContent:"center"},children:n.jsx(s.Alert,{severity:"error",children:"No data"})}):n.jsx(n.Fragment,{children:i.map(([c,a],d)=>n.jsxs(F.default.Fragment,{children:[n.jsx(ie,{predicate:c,objects:a}),df===void 0?new Intl.Locale(navigator.language):typeof f=="string"?new Intl.Locale(f):f,[f]),[E,V]=l.useState(!1),N=l.useMemo(()=>p!==void 0,[p]),v=l.useMemo(()=>c&&!N,[c,N]),q=l.useMemo(()=>v||a,[v,a]),_=l.useMemo(()=>!v&&e===void 0||N,[v,e,N]),z=l.useMemo(()=>v||_?!1:E||r,[v,_,E,r]),Y=l.useMemo(()=>!(r||v||_),[r,v,_]),fe=l.useMemo(()=>e!==void 0&&!_&&!v,[e,_,v]),pe=l.useMemo(()=>!q&&e!==void 0,[q,e]);l.useEffect(()=>{z&&(d==null||d())},[z]);const ue=l.useMemo(()=>Math.round(Math.random()*200)+240,[]),H=l.useMemo(()=>({children:O,...D})=>n.jsx("span",{className:g.linkComponentContainer,children:n.jsx(u,{...D,children:O})}),[]),M=l.useMemo(()=>({data:t,iri:e,LinkComponent:H,prefixes:b,labelIRIs:j,locale:x}),[t,e,H,b,j,x]),$=l.useMemo(()=>{if(i!==void 0)return i;if(M.iri!==void 0)return k(M,M.iri)},[M,i]);return n.jsx(G.Provider,{value:M,children:n.jsx(s.Paper,{className:S(g.container,h.className),...h,children:n.jsxs(s.Box,{className:g.innerContainer,children:[n.jsx(s.Box,{className:S(g.header,Y&&g.clickable),onClick:()=>Y&&V(O=>!O),children:n.jsxs(s.Typography,{variant:"h4",className:g.title,children:[fe&&n.jsxs(n.Fragment,{children:[n.jsx(B,{bigger:!0,value:e}),n.jsx(H,{href:e,label:$,children:$!==void 0?$:C(M,e)})]}),v&&n.jsxs(s.Box,{className:g.skeletons,children:[n.jsx(s.Skeleton,{width:28}),n.jsx(s.Skeleton,{width:ue})]}),_&&n.jsx(s.Box,{className:g.dialog,children:n.jsx(s.Alert,{severity:"error",children:p!=null?p:"No data"})})]})}),n.jsx(s.Collapse,{in:z,children:n.jsxs(s.Box,{className:g.body,children:[q&&n.jsx(s.Box,{className:g.skeletonsVertical,children:Array.from({length:5}).map((O,D)=>n.jsx(s.Skeleton,{height:28},D))}),pe&&n.jsx(ae,{})]})})]})})})}y.CopyButton=A,y.CopyIRIButton=B,y.default=de,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});