import{Q as W,w as q,r as o,y as F,H as B,e,D as Q,f as X,T as Y,aE as _,b8 as U,A as Z,o as $,a4 as P,a7 as ee,G as te,g as ae,aY as se,b9 as L,a_ as M,l as ne,P as r}from"./index-_6SmYgWK.js";const ie=({show:c,dialogProps:s,onCancel:g,onChunkEdit:O,onDeleteChunk:G,isReadOnly:p})=>{var j;const V=document.getElementById("portal"),d=W(t=>t.customization),u=q(),[a,C]=o.useState(),[x,b]=o.useState(),[n,h]=o.useState(!1),[f,m]=o.useState(""),[y,l]=o.useState({}),J=t=>{const i=t.src;Array.isArray(i)||typeof i=="object"?navigator.clipboard.writeText(JSON.stringify(i,null,"  ")):navigator.clipboard.writeText(i)},H=()=>{m(a==null?void 0:a.pageContent),l(a!=null&&a.metadata?JSON.parse(a==null?void 0:a.metadata):{}),h(!1)},K=()=>{O(f,y,a)};o.useEffect(()=>{var t,i,S,k,D,E,v,I,T,A,N,w,z;return s.data&&(C((t=s.data)==null?void 0:t.selectedChunk),m((S=(i=s.data)==null?void 0:i.selectedChunk)==null?void 0:S.pageContent),b(s==null?void 0:s.data.selectedChunkNumber),(D=(k=s.data)==null?void 0:k.selectedChunk)!=null&&D.metadata&&(typeof((v=(E=s.data)==null?void 0:E.selectedChunk)==null?void 0:v.metadata)=="string"?l(JSON.parse((T=(I=s.data)==null?void 0:I.selectedChunk)==null?void 0:T.metadata)):typeof((N=(A=s.data)==null?void 0:A.selectedChunk)==null?void 0:N.metadata)=="object"&&l((z=(w=s.data)==null?void 0:w.selectedChunk)==null?void 0:z.metadata))),()=>{C(),b(),m(""),l({}),h(!1)}},[s]),o.useEffect(()=>(u(c?{type:F}:{type:B}),()=>u({type:B})),[c,u]);const R=c?e.jsxs(Q,{fullWidth:!0,maxWidth:"md",open:c,onClose:g,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsx(X,{style:{fontSize:"1rem"},id:"alert-dialog-title",children:a&&x&&e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[e.jsxs(Y,{sx:{flex:1},variant:"h4",children:["#",x,". ",a.id]}),!n&&!p&&e.jsx(_,{permissionId:"documentStores:preview-process",onClick:()=>h(!0),size:"small",color:"primary",title:"Edit Chunk",sx:{ml:2},children:e.jsx(U,{})}),n&&!p&&e.jsx(Z,{onClick:()=>H(),color:"primary",title:"Cancel",sx:{ml:2},children:"Cancel"}),n&&!p&&e.jsx($,{permissionId:"documentStores:preview-process",onClick:()=>K(),color:"primary",title:"Save",variant:"contained",sx:{ml:2,mr:1},children:"Save"}),!n&&!p&&e.jsx(_,{permissionId:"documentStores:delete-loader",onClick:()=>G(a),size:"small",color:"error",title:"Delete Chunk",sx:{ml:1},children:e.jsx(P,{})}),e.jsx(ee,{onClick:g,size:"small",color:"inherit",title:"Close",sx:{ml:1},children:e.jsx(te,{})})]})}),e.jsx(ae,{children:a&&x&&e.jsxs("div",{children:[e.jsxs("div",{style:{paddingLeft:"10px",paddingRight:"10px",paddingTop:"5px",paddingBottom:"5px",fontSize:"15px",width:"max-content",borderRadius:"25px",boxShadow:d.isDarkMode?"0 2px 14px 0 rgb(255 255 255 / 20%)":"0 2px 14px 0 rgb(32 40 45 / 20%)",display:"flex",flexDirection:"row",alignItems:"center",marginTop:"5px",marginBottom:"10px"},children:[e.jsx(se,{style:{marginRight:5},size:15}),(j=a==null?void 0:a.pageContent)==null?void 0:j.length," characters"]}),e.jsx("div",{style:{marginTop:"5px"}}),!n&&e.jsx(L,{disabled:!0,height:"max-content",value:f,theme:d.isDarkMode?"dark":"light",basicSetup:{lineNumbers:!1,foldGutter:!1,autocompletion:!1,highlightActiveLine:!1}}),n&&e.jsx(L,{disabled:!1,autoFocus:!0,height:"max-content",value:f,theme:d.isDarkMode?"dark":"light",basicSetup:{lineNumbers:!1,foldGutter:!1,autocompletion:!1,highlightActiveLine:!1},onValueChange:t=>m(t)}),e.jsxs("div",{onClick:t=>t.stopPropagation(),onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&t.stopPropagation()},role:"presentation",style:{marginTop:"20px",marginBottom:"15px"},children:[!n&&e.jsx(M,{theme:d.isDarkMode?"ocean":"rjv-default",src:y,style:{padding:"10px"},name:null,quotesOnKeys:!1,enableClipboard:!1,displayDataTypes:!1,collapsed:1}),n&&e.jsx(M,{theme:d.isDarkMode?"ocean":"rjv-default",src:y,style:{padding:"10px"},name:null,quotesOnKeys:!1,displayDataTypes:!1,enableClipboard:t=>J(t),onEdit:t=>{l(t.updated_src)},onAdd:()=>{},onDelete:t=>{l(t.updated_src)}})]})]})})]}):null;return ne.createPortal(R,V)};ie.propTypes={show:r.bool,dialogProps:r.object,onCancel:r.func,onChunkEdit:r.func,onDeleteChunk:r.func,isReadOnly:r.bool};export{ie as E};
