import{R as m,j as e,S as n,h as p,C as f,T as v,H as g,f as C,a6 as y}from"./vendor-ClLR6ncd.js";import"./lodash-ZyeDnt0e.js";import{d as b}from"./Delete-BD9BsoWc.js";import{j,s as w,S as O}from"./model-Cn8i8hm_.js";import{E as d,I as L}from"./Messages-BRmQDxrZ.js";import{j as H,i as S,b as A,h as I,f as R,g as E}from"./index-OtVJl4GC.js";import{o as J}from"./object_hash-DuPyIO4t.js";import"./ui-DKzyPIqx.js";import"./model-Dfrorm_S.js";import{C as G}from"./Card-DCyqxUVE.js";import{C as N}from"./CardContent-B36bxiGw.js";import{C as P}from"./CardActions-DbEyUhB8.js";import"./ui-BOPU8Yl4.js";import"./index-CQ79H_Lz.js";import"./model-AmaTU-rL.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./useNamespaces-B-2wwTCG.js";import"./model-DgFcCvKB.js";import"./WithMeasure-BDk9QPMF.js";import"./Autocomplete-Cjt7Q9VV.js";import"./Chip-DoCs8Smb.js";import"./highlightSearch-BTHB3jgf.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./Box-Co2WcNPC.js";import"./TypographyWithTooltip-BFAG3Va9.js";import"./Link-BLwKPJFF.js";function M(s){const a=C(),t=A();return I(async()=>{const r=s.map(o=>JSON.parse(o));await S({url:R(E(t),"shacl-shapes"),method:"put",data:JSON.stringify(r)})},{invalidateRepoKeysOnSuccess:["shacl-shape"],onSuccess:()=>{a("../",{relative:"path"})}})}const T=s=>{try{return JSON.parse(s)}catch{return null}};function Q({disable:s,shaclShapeStr:a,removeShape:t,changeShape:r}){return e.jsxs(G,{sx:{width:450},children:[e.jsx(y,{title:w(T(a))||"anonymous"}),e.jsx(N,{sx:{pt:0,pb:0,display:"flex",flexDirection:"column",gap:1,maxHeight:"27vh",overflow:"auto"},children:e.jsx(O,{readOnly:s,value:a,onChange:r})}),e.jsx(P,{disableSpacing:!0,sx:{justifyContent:"flex-end"},children:e.jsx(g,{disabled:s,variant:"outlined",startIcon:e.jsx(b,{}),onClick:t,children:"remove"})})]})}function W(){return H(["generated-shacl-shape"],async s=>await S({url:`${s}/shacl-shapes/generate`,headers:{Accept:"application/ld+json"}}))}const x={},$=s=>Object.assign({},...s.map((a,t)=>({[`${t}-${J(a)}`]:JSON.stringify(a,null,2)})));function me(){var h;const s=W(),[a,t]=m.useState(x);m.useEffect(()=>{s.isSuccess&&a===x&&t($(s.data))},[a,s.data,s.isSuccess]);const r=M(Object.values(a));if(s.isLoading)return e.jsxs(n,{spacing:2,sx:{flexGrow:1},children:[e.jsx(n,{direction:"row",spacing:2,alignItems:"center",justifyContent:"space-between",children:e.jsx(p,{noWrap:!0,variant:"h4",children:"Generating SHACL shapes"})}),e.jsxs(n,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(f,{}),e.jsx(p,{children:"Server creates SHACL shapes based on data..."})]})]});const o=Object.values(a).some(i=>j()({state:{doc:i}}).length!==0)||Object.values(a).length===0;return e.jsxs(n,{spacing:2,sx:{flexGrow:1},children:[e.jsxs(n,{direction:"row",spacing:2,alignItems:"center",justifyContent:"space-between",children:[e.jsx(p,{noWrap:!0,variant:"h4",children:"Generated SHACL shapes"}),e.jsx(v,{title:o?"There are invalid shapes":void 0,children:e.jsx("span",{children:e.jsx(g,{variant:"contained",disabled:o||r.isLoading,onClick:r.mutate,children:"Save all shapes"})})})]}),s.isError||((h=s.data)==null?void 0:h.length)===0?e.jsxs(n,{children:[e.jsx(p,{children:"Failed to generate SHACL shapes"}),s.error?e.jsx(d,{error:s.error}):null]}):e.jsxs(e.Fragment,{children:[e.jsx(d,{error:r.error,resetError:r.reset}),e.jsx(L,{message:r.isLoading?"Saving SHACL shapes...":""}),e.jsx(n,{direction:"row",gap:2,flexWrap:"wrap",children:Object.entries(a).map(([i,u])=>e.jsxs(n,{children:[e.jsx(d,{error:j()({state:{doc:u}}).length===0?null:"Invalid SHACL shape"}),e.jsx(Q,{disable:r.isLoading,shaclShapeStr:u,removeShape:()=>{t(l=>{const c=Object.assign({},l);return delete c[i],c})},changeShape:l=>{t(c=>Object.assign({},c,{[i]:l}))}})]},i))})]})]})}export{me as default};
