import{a as p,r as m,k as D,j as a,M as E,b as T,I as $,B as S,P as K,F as O}from"./main-BzPVmAp-.js";import{S as q,F as J}from"./Table-kIlrKW-9.js";const G=e=>p.delete(`/sample/delete-sample-by-sample-id/${e}`),H=e=>p.post("/sample/bind-sample-to-analysis-result",e),Z=e=>p.post("/sample/add-sample-metadata",e),ee=e=>p.post("/sample/update-sample-metadata",e),ae=e=>p.get(`/sample/find-sample-metadata-by-id/${e}`),Q=e=>p.post("/sample/update-sample-metadata-list",e),R=e=>p.get(`/list-by-project?project=${e}`),A=({operatePipeline:e,rowSelection:d})=>{const[r,o]=m.useState([]),[h,b]=m.useState([]),[_,k]=m.useState(!1),{project:u,messageApi:c,projectObj:i}=D(),I=m.useRef(null),w=()=>{var t;return!(i!=null&&i.metadata_form)||!Array.isArray(i==null?void 0:i.metadata_form)?[]:(t=i==null?void 0:i.metadata_form)==null?void 0:t.map(l=>({title:l.label,dataIndex:l.name,key:l.name,ellipsis:!0}))};T();const{Search:W}=$,y=async()=>{k(!0);const t=await R(u);console.log(t),o(t.data),I.current=t.data,b(t.data),k(!1)},C=[{title:"ID",dataIndex:"sample_id",key:"sample_id",ellipsis:!0,width:100},{title:"Project",dataIndex:"project",key:"project",ellipsis:!0,width:100},{title:"Sample Name",dataIndex:"sample_name",key:"sample_name",ellipsis:!0,width:100},...w(),{title:"Action",key:"action",fixed:"right",width:200,render:(t,l)=>a.jsxs(q,{size:"middle",children:[a.jsx(S,{size:"small",color:"cyan",variant:"solid",onClick:()=>{e.openModal("metadataForm",{analysis_key:l.analysis_key,sample_id:l.sample_id,callback:y})},children:"Edit"}),a.jsx(K,{title:"Are you sure about the deletion?",onConfirm:async()=>{await G(l.sample_id),y()},children:a.jsx(S,{size:"small",color:"danger",variant:"solid",children:"Delete"})})]})}];m.useEffect(()=>{const t=l=>{var B;const n=((B=l.clipboardData)==null?void 0:B.getData("Text"))||"";if(!n)return;const f=n.includes("	")?"	":",",x=n.split(/\r?\n/).filter(s=>s.trim()!=="").map(s=>s.split(f).map(g=>g.trim())),v=[{title:"Sample Name",dataIndex:"sample_name",key:"sample_name",render:s=>a.jsx("span",{children:s})},...w()].map(s=>s.dataIndex),L=Object.fromEntries(x.map(s=>[s[0],s])),N=I.current.map(s=>{const g=L[s.sample_name];if(console.log(g),!g)return s;const z={};for(let j=1;j<v.length;j++)z[v[j]]=g[j];return{...s,...z}});o(N),c.success("Paste was successful!")};return document.addEventListener("paste",t),()=>{document.removeEventListener("paste",t)}},[]);const F=async()=>{const t=w().map(n=>n.dataIndex),l=r.map(n=>{const f={};t.forEach((x,P)=>{x in n&&(f[x]=n[x])});let M=null;return Object.keys(f).length!=0&&(M=JSON.stringify(f)),{sample_id:n.sample_id,metadata:M}}).filter(n=>n.metadata!=null);if(l.length==0){c.error("No Data!");return}console.log(l),await Q(l),c.success("update successfully!")};return m.useEffect(()=>{y()},[]),a.jsxs(a.Fragment,{children:[a.jsxs(O,{justify:"end",align:"center",gap:"small",style:{marginBottom:"1rem"},children:[a.jsx(S,{size:"small",color:"cyan",variant:"solid",onClick:F,children:"Batch Save"}),a.jsx(S,{size:"small",color:"cyan",variant:"solid",onClick:()=>{e.openModal("metadataForm",{callback:y})},children:"Add Sample"}),a.jsx(S,{size:"small",color:"primary",variant:"solid",onClick:y,children:"Refresh"})]}),a.jsx(J,{rowSelection:d,rowKey:t=>t.sample_id,size:"small",bordered:!0,pagination:{pageSize:30},loading:_,scroll:{x:"max-content",y:55*5},columns:C,footer:()=>`A total of ${r.length} records`,dataSource:r})]})},U=({visible:e,onClose:d,operatePipeline:r,params:o})=>{const[h,b]=m.useState(),{messageApi:_}=D(),k=async()=>{var c;if(!h){_.error("Please select a sample");return}const u={analysis_result_id:o.analysis_result_id,sample_id:h[0]};console.log(u),await H(u),_.success("Bind successfully"),(c=o.callback)==null||c.call(o),d()};return a.jsx(E,{title:"Binding Sample",open:e,onClose:d,onCancel:d,width:"80%",onOk:k,children:a.jsx(A,{rowSelection:{type:"radio",onChange:(u,c)=>{b(u)}},operatePipeline:r})})},V=({visible:e,onClose:d,params:r})=>{if(!e)return null;const{operatePipeline:o,...h}=r;return a.jsx(E,{title:"metadata",open:e,onClose:d,onCancel:d,width:"80%",footer:null,children:a.jsx(A,{operatePipeline:o})})},te=Object.freeze(Object.defineProperty({__proto__:null,BindSample:U,MetadataModal:V,default:A,getSamples:R},Symbol.toStringTag,{value:"Module"}));export{U as B,V as M,Z as a,ae as f,R as g,te as i,ee as u};
