import{a$ as qe,w as J,x as K,r as s,y as ue,H as G,e,D as he,f as pe,bL as xe,g as me,B as W,T as L,O as re,i as ge,A as f,p as V,F as X,l as De,bM as F,G as E,J as Y,K as Z,P as N,a9 as Ve,bN as Ge,ab as We,k as Le,am as He,an as Qe,N as Je,Q as Ke,aD as Xe,U as Ye,u as ie,aC as Ze,bO as et,M as tt,E as at,S as le,V as st,bP as nt,q as ce,o as ot,a4 as rt,bQ as it,be as lt,ar as ct,as as dt,at as ut,aO as ht,av as pt,bm as h,bR as de,au as xt,bl as Q,t as T,bS as mt,bT as gt}from"./index-_6SmYgWK.js";/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Dt=qe("outline","arrows-down-up","IconArrowsDownUp",[["path",{d:"M17 3l0 18",key:"svg-0"}],["path",{d:"M10 18l-3 3l-3 -3",key:"svg-1"}],["path",{d:"M7 21l0 -18",key:"svg-2"}],["path",{d:"M20 6l-3 -3l-3 3",key:"svg-3"}]]);const je=({show:p,dialogProps:i,onCancel:x,onConfirm:A})=>{const O=document.getElementById("portal"),l=J();K();const D=(...o)=>l(Y(...o)),m=(...o)=>l(Z(...o)),[M,w]=s.useState(""),[B,y]=s.useState(""),[b,I]=s.useState(""),[a,v]=s.useState(""),[P,S]=s.useState("ADD"),[c,j]=s.useState({});s.useEffect(()=>(i.type==="EDIT"&&i.data?(w(i.data.datasetId),y(i.data.datasetName),S("EDIT"),j(i.data),I(i.data.input),v(i.data.output)):i.type==="ADD"&&(w(i.data.datasetId),y(i.data.datasetName),S("ADD"),j({})),()=>{I(""),v(""),S("ADD"),j({})}),[i]),s.useEffect(()=>(l(p?{type:ue}:{type:G}),()=>l({type:G})),[p,l]);const d=async()=>{try{const o={datasetId:M,input:b,output:a},g=await F.createDatasetRow(o);g.data&&(D({message:"New Row added for the given Dataset",options:{key:new Date().getTime()+Math.random(),variant:"success",action:k=>e.jsx(f,{style:{color:"white"},onClick:()=>m(k),children:e.jsx(E,{})})}}),A(g.data.id))}catch(o){D({message:`Failed to add new row in the Dataset: ${typeof o.response.data=="object"?o.response.data.message:o.response.data}`,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:g=>e.jsx(f,{style:{color:"white"},onClick:()=>m(g),children:e.jsx(E,{})})}}),x()}},C=async()=>{try{const o={input:b,output:a},g=await F.updateDatasetRow(c.id,o);g.data&&(D({message:"Dataset Row saved",options:{key:new Date().getTime()+Math.random(),variant:"success",action:k=>e.jsx(f,{style:{color:"white"},onClick:()=>m(k),children:e.jsx(E,{})})}}),A(g.data.id))}catch(o){D({message:`Failed to save Dataset Row: ${typeof o.response.data=="object"?o.response.data.message:o.response.data}`,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:g=>e.jsx(f,{style:{color:"white"},onClick:()=>m(g),children:e.jsx(E,{})})}}),x()}},U=p?e.jsxs(he,{fullWidth:!0,maxWidth:"sm",open:p,onClose:x,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsx(pe,{sx:{fontSize:"1rem"},id:"alert-dialog-title",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[e.jsx(xe,{style:{marginRight:"10px"}}),i.type==="ADD"?`Add Item to ${B} Dataset`:`Edit Item in ${B} Dataset`]})}),e.jsxs(me,{children:[e.jsxs(W,{sx:{p:2},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(L,{children:["Input",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(re,{size:"small",sx:{mt:1},multiline:!0,rows:4,type:"string",fullWidth:!0,onChange:o=>I(o.target.value),value:b??""},"input")]}),e.jsxs(W,{sx:{p:2},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(L,{children:["Anticipated Output",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(re,{size:"small",sx:{mt:1},multiline:!0,rows:4,type:"string",fullWidth:!0,onChange:o=>v(o.target.value),value:a??""},"output")]})]}),e.jsxs(ge,{children:[e.jsx(f,{onClick:()=>x(),children:i.cancelButtonName}),e.jsx(V,{permissionId:"datasets:create,datasets:update",disabled:!b||!a,variant:"contained",onClick:()=>P==="ADD"?d():C(),children:i.confirmButtonName})]}),e.jsx(X,{})]}):null;return De.createPortal(U,O)};je.propTypes={show:N.bool,dialogProps:N.object,onCancel:N.func,onConfirm:N.func};const jt=`Only the first 2 columns will be considered:
----------------------------
| Input      | Output      |
----------------------------
| test input | test output |
----------------------------
`,fe=({show:p,dialogProps:i,onCancel:x,onConfirm:A})=>{const O=document.getElementById("portal"),l=J();K();const D=(...d)=>l(Y(...d)),m=(...d)=>l(Z(...d)),[M,w]=s.useState(""),[B,y]=s.useState(""),[b,I]=s.useState(!1),[a,v]=s.useState(),[P,S]=s.useState("ADD");s.useEffect(()=>(w(i.data.datasetId),y(i.data.datasetName),S("ADD"),()=>{S("ADD"),w(""),y(""),I(!1),v()}),[i]),s.useEffect(()=>(l(p?{type:ue}:{type:G}),()=>l({type:G})),[p,l]);const c=async()=>{try{const d={datasetId:M,firstRowHeaders:b,csvFile:a},C=await F.createDatasetRow(d);C.data&&(D({message:"New Row added for the given Dataset",options:{key:new Date().getTime()+Math.random(),variant:"success",action:U=>e.jsx(f,{style:{color:"white"},onClick:()=>m(U),children:e.jsx(E,{})})}}),A(C.data.id))}catch(d){D({message:`Failed to add new row in the Dataset: ${typeof d.response.data=="object"?d.response.data.message:d.response.data}`,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:C=>e.jsx(f,{style:{color:"white"},onClick:()=>m(C),children:e.jsx(E,{})})}}),x()}},j=p?e.jsxs(he,{fullWidth:!0,maxWidth:"sm",open:p,onClose:x,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsx(pe,{sx:{fontSize:"1rem"},id:"alert-dialog-title",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[e.jsx("div",{style:{width:50,height:50,marginRight:10,borderRadius:"50%",backgroundColor:"white"},children:e.jsx(xe,{style:{width:"100%",height:"100%",padding:7,borderRadius:"50%",objectFit:"contain"}})}),"Upload Items to ["+B+"] Dataset"]})}),e.jsx(me,{children:e.jsxs(W,{sx:{p:2},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(L,{children:["Upload CSV",e.jsx(Ve,{style:{mb:1,mt:2},title:`<pre>${jt}</pre>`})]}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(Ge,{disabled:!1,fileType:".csv",onChange:d=>v(d),value:a??"Choose a file to upload"}),e.jsx(We,{value:b,onChange:I,label:"Treat First Row as headers in the upload file?"})]})}),e.jsxs(ge,{children:[e.jsx(f,{onClick:()=>x(),children:i.cancelButtonName}),e.jsx(Le,{disabled:!a,variant:"contained",onClick:()=>P==="ADD"?c():saveDatasetRow(),children:i.confirmButtonName})]}),e.jsx(X,{})]}):null;return De.createPortal(j,O)};fe.propTypes={show:N.bool,dialogProps:N.object,onCancel:N.func,onConfirm:N.func};var ee={},ft=He;Object.defineProperty(ee,"__esModule",{value:!0});var we=ee.default=void 0,wt=ft(Qe()),yt=e,bt=(0,wt.default)((0,yt.jsx)("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zm-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"}),"DragIndicator");we=ee.default=bt;const St=()=>{var oe;const p=Je(),i=Ke(t=>t.customization),x=J();K();const{error:A}=Xe(),[O,l]=s.useState(!1),[D,m]=s.useState(!1),[M,w]=s.useState({}),[B,y]=s.useState(!1),[b,I]=s.useState({}),[a,v]=s.useState([]),[P,S]=s.useState(!0),[c,j]=s.useState([]),d=(...t)=>x(Y(...t)),C=(...t)=>x(Z(...t)),{confirm:U}=Ye(),o=ie(F.getDataset),g=ie(F.reorderDatasetRow),k=document.location.pathname.toString().split("/"),_=k[k.length-1]==="dataset_rows"?"":k[k.length-1],{hasPermission:ye}=Ze(),be=s.useRef(),te=s.useRef(),[ve,R]=s.useState(!1),[Se,Ce]=s.useState(-1),[Ie,ae]=s.useState(-1),[$,ke]=s.useState(1),[z,Re]=s.useState(et),[Te,Ee]=s.useState(0),Ne=(t,r)=>{ke(t),Re(r),H(t,r)},H=(t,r)=>{S(!0);const n={page:t||$,limit:r||z};o.request(_,n)},Ae=(t,r)=>{be.current=r,Ce(r),ae(-1)},Be=(t,r)=>{ae(r),te.current=r},Me=(t,r)=>{te.current=r;const n={...a};n.rows.splice(Ie,0,a.rows.splice(Se,1)[0]),v({...n}),t.preventDefault();const u=[];a.rows.map(($e,ze)=>{u.push({id:$e.id,sequenceNo:ze})}),g.request({datasetId:_,rows:u})},Pe=t=>{if(t.target.checked){const r=((a==null?void 0:a.rows)||[]).map(n=>n.id);j(r);return}j([])},Fe=(t,r)=>{const n=c.indexOf(r);let u=[];n===-1?u=u.concat(c,r):n===0?u=u.concat(c.slice(1)):n===c.length-1?u=u.concat(c.slice(0,-1)):n>0&&(u=u.concat(c.slice(0,n),c.slice(n+1))),j(u)},se=()=>{const t={type:"ADD",cancelButtonName:"Cancel",confirmButtonName:"Add",data:{datasetId:_,datasetName:a.name}};w(t),l(!0)},Oe=()=>{const t={type:"ADD",cancelButtonName:"Cancel",confirmButtonName:"Upload",data:{datasetId:_,datasetName:a.name}};w(t),m(!0)},Ue=()=>{I({type:"EDIT",cancelButtonName:"Cancel",confirmButtonName:"Save",data:a}),y(!0)},ne=t=>{const r={type:"EDIT",cancelButtonName:"Cancel",confirmButtonName:"Save",data:{datasetName:a.name,...t}};w(r),l(!0)},_e=async()=>{const t={title:"Delete",description:`Delete ${c.length} dataset items?`,confirmButtonName:"Delete",cancelButtonName:"Cancel"};if(await U(t)){try{(await F.deleteDatasetItems(c)).data&&(d({message:"Dataset Items deleted",options:{key:new Date().getTime()+Math.random(),variant:"success",action:u=>e.jsx(f,{style:{color:"white"},onClick:()=>C(u),children:e.jsx(E,{})})}}),q())}catch(n){d({message:`Failed to delete dataset items: ${typeof n.response.data=="object"?n.response.data.message:n.response.data}`,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:u=>e.jsx(f,{style:{color:"white"},onClick:()=>C(u),children:e.jsx(E,{})})}})}j([])}},q=()=>{l(!1),m(!1),y(!1),H($,z)};return s.useEffect(()=>{H($,z)},[]),s.useEffect(()=>{if(o.data){const t=o.data;v(t),Ee(t.total)}},[o.data]),s.useEffect(()=>{S(o.loading)},[o.loading]),e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:A?e.jsx(at,{error:A}):e.jsxs(le,{flexDirection:"column",sx:{gap:3},children:[e.jsxs(st,{isBackButton:!0,isEditButton:ye("datasets:create,datasets:update"),onEdit:Ue,onBack:()=>window.history.back(),search:!1,title:`Dataset : ${(a==null?void 0:a.name)||""}`,description:a==null?void 0:a.description,children:[e.jsx(V,{permissionId:"datasets:create,datasets:update",variant:"outlined",color:"secondary",sx:{borderRadius:2,height:"100%"},onClick:Oe,startIcon:e.jsx(nt,{}),children:"Upload CSV"}),e.jsx(V,{permissionId:"datasets:create,datasets:update",variant:"contained",sx:{borderRadius:2,height:"100%"},onClick:se,startIcon:e.jsx(ce,{}),children:"New Item"})]}),c.length>0&&e.jsxs(ot,{permissionId:"datasets:delete",sx:{mt:1,mb:2,width:"max-content"},variant:"outlined",onClick:_e,color:"error",startIcon:e.jsx(rt,{}),children:["Delete ",c.length," ",c.length===1?"item":"items"]}),!P&&((oe=a==null?void 0:a.rows)==null?void 0:oe.length)<=0?e.jsxs(le,{sx:{alignItems:"center",justifyContent:"center"},flexDirection:"column",children:[e.jsx(W,{sx:{p:2,height:"auto"},children:e.jsx("img",{style:{objectFit:"cover",height:"20vh",width:"auto"},src:it,alt:"empty_datasetSVG"})}),e.jsx("div",{children:"No Dataset Items Yet"}),e.jsx(V,{permissionId:"datasets:create,datasets:update",variant:"contained",sx:{borderRadius:2,height:"100%",mt:2,color:"white"},startIcon:e.jsx(ce,{}),onClick:se,children:"New Item"})]}):e.jsxs(lt.Fragment,{children:[e.jsx(ct,{sx:{border:1,borderColor:p.palette.grey[900]+25,borderRadius:2},component:dt,children:e.jsxs(ut,{sx:{minWidth:650},"aria-label":"simple table",children:[e.jsx(ht,{sx:{backgroundColor:i.isDarkMode?p.palette.common.black:p.palette.grey[100],height:56},children:e.jsxs(pt,{children:[e.jsx(h,{padding:"checkbox",children:e.jsx(de,{color:"primary",checked:c.length===((a==null?void 0:a.rows)||[]).length,onChange:Pe,inputProps:{"aria-label":"select all"}})}),e.jsx(h,{children:"Input"}),e.jsx(h,{children:"Expected Output"}),e.jsx(h,{style:{width:"1%"},children:e.jsx(Dt,{})})]})}),e.jsx(xt,{children:P?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{children:[e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})})]}),e.jsxs(Q,{children:[e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})}),e.jsx(h,{children:e.jsx(T,{variant:"text"})})]})]}):e.jsx(e.Fragment,{children:((a==null?void 0:a.rows)||[]).map((t,r)=>e.jsxs(Q,{draggable:ve,onDragStart:n=>Ae(n,r),onDragOver:n=>n.preventDefault(),onDragEnter:n=>Be(n,r),onDragEnd:n=>Me(n,r),hover:!0,sx:{cursor:"pointer","&:last-child td, &:last-child th":{border:0}},children:[e.jsx(h,{padding:"checkbox",onMouseDown:()=>R(!1),onMouseUp:()=>R(!0),children:e.jsx(de,{color:"primary",checked:c.indexOf(t.id)!==-1,onChange:n=>Fe(n,t.id),inputProps:{"aria-labelledby":t.id}})}),e.jsx(h,{onClick:()=>ne(t),onMouseDown:()=>R(!1),onMouseUp:()=>R(!0),children:t.input}),e.jsx(h,{onClick:()=>ne(t),onMouseDown:()=>R(!1),onMouseUp:()=>R(!0),children:t.output}),e.jsx(h,{style:{width:"1%"},children:e.jsx(we,{onMouseDown:()=>R(!0),onMouseUp:()=>R(!1)})})]},r))})})]})}),e.jsx(L,{sx:{color:p.palette.grey[600],marginTop:-2},variant:"subtitle2",children:e.jsx("i",{children:"Use the drag icon at (extreme right) to reorder the dataset items"})}),e.jsx(mt,{currentPage:$,limit:z,total:Te,onChange:Ne})]})]})}),e.jsx(je,{show:O,dialogProps:M,onCancel:()=>l(!1),onConfirm:q}),D&&e.jsx(fe,{show:D,dialogProps:M,onCancel:()=>m(!1),onConfirm:q}),B&&e.jsx(gt,{show:B,dialogProps:b,onCancel:()=>y(!1),onConfirm:q}),e.jsx(X,{})]})};export{St as default};
