import{r,k as F,j as e,F as k,cd as D,R as H,C as S,d as x,e as L,E as $,a as V,b as W,I,t as z,D as O}from"./main-BzPVmAp-.js";import{E as P}from"./index-Djhsc5K4.js";import{S as T}from"./index-BZ6Sq__j.js";import{C as j}from"./index-7u0Bo8e4.js";import{R as _}from"./RedoOutlined-d_QTXv-s.js";import"./study-page-D4nenWxt.js";import"./usePagination-CGdUxo17.js";import"./Table-kIlrKW-9.js";import"./addEventListener-CzbSevz3.js";import"./Dropdown-Clv_Pvnt.js";import"./index-sAnz6zLe.js";import"./index-SGIbgpRk.js";const{Search:q}=I,A=r.forwardRef(({pathwayId:i,organisms:o,highlightKeys:a=[],compound:s},n)=>{const[c,d]=r.useState(""),[h,E]=r.useState([]),g=r.useRef(null),[p,R]=r.useState({width:0,height:0}),[C,f]=r.useState(!1),{messageApi:G}=F();r.useImperativeHandle(n,()=>({reload:y}));const K=async t=>{f(!0);try{const l=await V.get(`/kegg/kgml/${t}`);d(l.data.image),E(l.data.entries)}catch{G.error("数据获取失败!")}f(!1)},y=()=>{i&&o&&K(`${o}${i}`)};r.useEffect(()=>{y()},[i,o]);const w=g.current?g.current.width/p.width:1,b=g.current?g.current.height/p.height:1,M=r.useMemo(()=>{if(!s||s&&s.length==0)return h;const t=new Map(Object.entries(s));return h.map(l=>{let m=null;for(const v of l.name)if(m=t.get(v),m)break;return m?{isHighlight:!0,color:m>0?"#ff4d4f":"#1890ff",direction:m,...l}:{...l}})},[h,s]),u=3;return e.jsx(T,{spinning:C,children:e.jsxs(k,{justify:"center",vertical:!0,children:[e.jsxs("div",{style:{marginTop:12,display:"flex",gap:24,alignItems:"center",flexWrap:"wrap",justifyContent:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:14,height:14,background:"#ff4d4f",border:"1px solid #999",borderRadius:2}}),e.jsx("span",{children:"compound (Upregulated)"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:14,height:14,background:"#1890ff",border:"1px solid #999",borderRadius:2}}),e.jsx("span",{children:"compound (Downregulated)"})]})]}),e.jsx(k,{justify:"center",children:e.jsx("div",{style:{position:"relative",display:"inline-block"},children:c&&e.jsxs(e.Fragment,{children:[e.jsx("img",{ref:g,src:c,alt:"KEGG pathway",style:{maxWidth:"100%",height:"auto"},onLoad:t=>{const l=t.currentTarget;R({width:l.naturalWidth,height:l.naturalHeight})}}),e.jsx("svg",{width:p.width,height:p.height,style:{position:"absolute",top:0,left:0},children:M.map(t=>e.jsxs("a",{href:t.link,target:"_blank",children:[e.jsx("rect",{x:(t.x-t.width/2-u)*w,y:(t.y-t.height/2-u)*b,width:(t.width+u*2)*w,height:(t.height+u*2)*b,fill:t.isHighlight?t.color:"transparent",stroke:t.isHighlight?t.color:"transparent",strokeWidth:2,rx:4,ry:4,children:t.isHighlight&&e.jsx("animate",{attributeName:"opacity",values:"1;0.3;1",dur:"0.5s",repeatCount:"indefinite"})}),e.jsxs("title",{children:[t.label,t.direction?`(${t.direction})`:""]})]},t.id))})]})})})]})})}),N=i=>{const[o,a]=r.useState([]),{organisms:s,pathwayId:n}=i,c=r.useRef(null);return e.jsx(j,{size:"small",extra:e.jsxs(e.Fragment,{children:[e.jsx(z,{title:"刷新",children:e.jsx(_,{onClick:()=>c.current.reload()})}),e.jsx(q,{placeholder:"输入要高亮的基因/化合物ID，用逗号分隔",style:{width:250,marginLeft:10},allowClear:!0,onSearch:d=>a(d.split(","))})]}),title:`${s}${n}`,children:e.jsx(A,{ref:c,...i,highlightKeys:o})})},le=()=>{const[i,o]=r.useState(),[a]=D(),[s,n]=r.useState(),c=(d,h)=>{console.log(d),console.log(h),n(h)};return e.jsx(e.Fragment,{children:e.jsxs(H,{children:[e.jsx(S,{lg:6,sm:6,xs:24,style:{paddingRight:"1rem"},children:e.jsx(j,{size:"small",children:e.jsxs(x,{form:a,onValuesChange:c,children:[e.jsx(x.Item,{name:"organisms",label:"organisms",rules:[{required:!0,message:"该字段不能为空!"}],tooltip:e.jsxs(e.Fragment,{children:["KEGG Organisms:",e.jsx("a",{target:"_blank",href:"https://www.genome.jp/kegg/tables/br08606.html",children:"br08606"})]}),children:e.jsx(L,{allowClear:!0,options:[{label:"hsa",value:"hsa"},{label:"mmu",value:"mmu"},{label:"rno",value:"rno"}]})}),e.jsx(x.Item,{rules:[{required:!0,message:"该字段不能为空!"}],name:"pathwayId",label:"Pathway Id",children:e.jsx(U,{})})]})})}),e.jsx(S,{lg:18,sm:18,xs:24,children:s!=null&&s.organisms&&(s!=null&&s.pathwayId)?e.jsx(N,{...s}):e.jsxs(j,{children:["   ",e.jsx($,{})]})})]})})},U=({value:i,onChange:o})=>{const{modal:a,openModal:s,closeModal:n}=W();return e.jsxs(e.Fragment,{children:[e.jsx(I,{value:i,onClick:()=>{s("entityDrawer",{name:"pathwayId"})}}),e.jsx(X,{visible:a.key=="entityDrawer"&&a.visible,params:a.params,onClose:n,onChange:o})]})},X=({visible:i,setRecord:o,onChange:a,params:s,onClose:n,callback:c})=>e.jsx(e.Fragment,{children:e.jsx(O,{open:i,onClose:n,width:"80%",children:i&&e.jsx(P,{tabKey:"mesh-KEGG",params:{category:["KEGG"]},disableWidth:!0,rowSelection:{onChange:(d,h)=>{a(h[0].entity_id.replaceAll("map","")),n()},type:"radio"}})})});export{A as KGMLMapSVG,le as default};
