import{a as p,r as m,w as B,j as a,M as C,L as $,I as K,B as _,P as O,z as J}from"./index-DWaKf7-t.js";import{S as N,F as q}from"./Table-DdQ_sLHU.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),D=e=>p.get(`/list-by-project?project=${e}`),I=({operatePipeline:e,rowSelection:r})=>{const[d,i]=m.useState([]),[h,w]=m.useState([]),[S,k]=m.useState(!1),{project:u,messageApi:c,projectObj:o}=B(),A=m.useRef(null),M=()=>{var t;return!(o!=null&&o.metadata_form)||!Array.isArray(o==null?void 0:o.metadata_form)?[]:(t=o==null?void 0:o.metadata_form)==null?void 0:t.map(l=>({title:l.label,dataIndex:l.name,key:l.name,ellipsis:!0}))};$();const{Search:W}=K,y=async()=>{k(!0);const t=await D(u);console.log(t),i(t.data),A.current=t.data,w(t.data),k(!1)},R=[{title:"ID",dataIndex:"sample_id",key:"sample_id",ellipsis:!0,width:100},{title:"项目",dataIndex:"project",key:"project",ellipsis:!0,width:100},{title:"样本名称",dataIndex:"sample_name",key:"sample_name",ellipsis:!0,width:100},...M(),{title:"操作",key:"action",fixed:"right",width:200,render:(t,l)=>a.jsxs(N,{size:"middle",children:[a.jsx(_,{size:"small",color:"cyan",variant:"solid",onClick:()=>{e.openModal("metadataForm",{analysis_key:l.analysis_key,sample_id:l.sample_id,callback:y})},children:"编辑"}),a.jsx(O,{title:"确定删除吗？",onConfirm:async()=>{await G(l.sample_id),y()},children:a.jsx(_,{size:"small",color:"danger",variant:"solid",children:"删除"})})]})}];m.useEffect(()=>{const t=l=>{var v;const n=((v=l.clipboardData)==null?void 0:v.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())),z=[{title:"样本名称",dataIndex:"sample_name",key:"sample_name",render:s=>a.jsx("span",{children:s})},...M()].map(s=>s.dataIndex),P=Object.fromEntries(x.map(s=>[s[0],s])),T=A.current.map(s=>{const g=P[s.sample_name];if(console.log(g),!g)return s;const E={};for(let j=1;j<z.length;j++)E[z[j]]=g[j];return{...s,...E}});i(T),c.success("粘贴成功！")};return document.addEventListener("paste",t),()=>{document.removeEventListener("paste",t)}},[]);const F=async()=>{const t=M().map(n=>n.dataIndex),l=d.map(n=>{const f={};t.forEach((x,L)=>{x in n&&(f[x]=n[x])});let b=null;return Object.keys(f).length!=0&&(b=JSON.stringify(f)),{sample_id:n.sample_id,metadata:b}}).filter(n=>n.metadata!=null);if(l.length==0){c.error("没有数据!");return}console.log(l),await Q(l),c.success("更新成功!")};return m.useEffect(()=>{y()},[]),a.jsxs(a.Fragment,{children:[a.jsxs(J,{justify:"end",align:"center",gap:"small",style:{marginBottom:"1rem"},children:[a.jsx(_,{size:"small",color:"cyan",variant:"solid",onClick:F,children:"批量保存"}),a.jsx(_,{size:"small",color:"cyan",variant:"solid",onClick:()=>{e.openModal("metadataForm",{callback:y})},children:"添加样本"}),a.jsx(_,{size:"small",color:"primary",variant:"solid",onClick:y,children:"刷新"})]}),a.jsx(q,{rowSelection:r,rowKey:t=>t.sample_id,size:"small",bordered:!0,pagination:{pageSize:30},loading:S,scroll:{x:"max-content",y:55*5},columns:R,footer:()=>`一共${d.length}条记录`,dataSource:d})]})},U=({visible:e,onClose:r,operatePipeline:d,params:i})=>{const[h,w]=m.useState(),{messageApi:S}=B(),k=async()=>{var c;if(!h){S.error("请选择样本");return}const u={analysis_result_id:i.analysis_result_id,sample_id:h[0]};console.log(u),await H(u),S.success("绑定成功"),(c=i.callback)==null||c.call(i),r()};return a.jsxs(C,{title:"绑定样本",open:e,onClose:r,onCancel:r,width:"80%",onOk:k,children:[JSON.stringify(i),a.jsx(I,{rowSelection:{type:"radio",onChange:(u,c)=>{w(u)}},operatePipeline:d})]})},V=({visible:e,onClose:r,params:d})=>{if(!e)return null;const{operatePipeline:i,...h}=d;return a.jsx(C,{title:"metadata",open:e,onClose:r,onCancel:r,width:"80%",footer:null,children:a.jsx(I,{operatePipeline:i})})},te=Object.freeze(Object.defineProperty({__proto__:null,BindSample:U,MetadataModal:V,default:I,getSamples:D},Symbol.toStringTag,{value:"Module"}));export{U as B,V as M,Z as a,ae as f,D as g,te as i,ee as u};
