import{m as S,o as R,R as e,ag as I,a_ as H,a$ as N,ai as P,ao as B,ak as G,r as g,P as T,b4 as F,u as C,b as M,a as E,b0 as A,b1 as O,b2 as j,b3 as _,F as L,G as U,bq as W,br as K,E as $,K as z}from"./rpcWorker-CVTx5FIM.js";import{D as V}from"./cjs-Is-kCwAU.js";import{a as Y,C as q}from"./ColorPicker-CsOTGrvA.js";const J=S()(t=>({closeButton:{position:"absolute",right:t.spacing(1),top:t.spacing(1),color:t.palette.grey[500]}}));function Q(t){const l=g.useRef(null);return e.createElement(V,{nodeRef:l,cancel:'[class*="MuiDialogContent-root"]',onStart:s=>{var o,a;return(a=(o=s.target)===null||o===void 0?void 0:o.className)===null||a===void 0?void 0:a.includes("MuiDialogTitle")}},e.createElement(T,{ref:l,...t}))}const X=R(function(l){const{classes:s}=J(),{title:o,children:a,onClose:r}=l;return e.createElement(I,{...l,PaperComponent:Q},e.createElement(H,null,e.createElement(N,{style:{cursor:"move"}},o,r?e.createElement(P,{className:s.closeButton,onClick:()=>{r()}},e.createElement(B,null)):null),e.createElement(G,null),a))});function y(t,l,s=1){const o=l.map(r=>t.findIndex(n=>n.name===r)).sort((r,n)=>r-n);let a=0;for(const r of o){const n=Math.max(a,r-s);n>=a&&t.splice(n,0,t.splice(r,1)[0]),a=a+1}return t}function D(t,l,s=1){const o=l.map(r=>t.findIndex(n=>n.name===r)).sort((r,n)=>n-r);let a=t.length-1;for(const r of o){const n=Math.min(a,r+s);n<=a&&t.splice(n,0,t.splice(r,1)[0]),a=a-1}return t}const Z=S()({cell:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}});function ee({rows:t,onChange:l,showTips:s}){const{classes:o}=Z(),[a,r]=g.useState([]),{name:n,color:c,baseUri:u,...m}=t[0],[h,i]=g.useState({idx:0,field:null});return e.createElement("div",null,e.createElement(te,{selected:a,rows:t,showTips:s,onChange:l}),e.createElement("div",{style:{height:400,width:"100%"}},e.createElement(F,{getRowId:d=>d.name,checkboxSelection:!0,disableRowSelectionOnClick:!0,onRowSelectionModelChange:d=>{r(d)},rows:t,rowHeight:25,columnHeaderHeight:33,columns:[{field:"color",headerName:"Color",renderCell:d=>{const{value:p,id:b}=d;return e.createElement(Y,{color:p||"blue",onChange:f=>{const v=t.find(w=>w.name===b);v&&(v.color=f),l([...t])}})}},{field:"name",headerName:"Name",width:C.measureGridWidth(t.map(d=>d.name))},...Object.keys(m).map(d=>({field:d,renderCell:({value:p})=>e.createElement("div",{className:o.cell},e.createElement(M.SanitizedHTML,{html:C.getStr(p)})),width:C.measureGridWidth(t.map(p=>`${p[d]}`))}))],sortModel:[],onSortModelChange:d=>{const p=d[0],b=(h.idx+1)%2,f=p.field||h.field;i({idx:b,field:f}),l(f?[...t].sort((v,w)=>{const k=C.getStr(v[f]),x=C.getStr(w[f]);return b===1?k.localeCompare(x):x.localeCompare(k)}):t)}})))}function te({selected:t,onChange:l,rows:s,showTips:o}){const[a,r]=g.useState(null),[n,c]=g.useState("blue");return e.createElement(e.Fragment,null,e.createElement(E,{disabled:!t.length,onClick:u=>{r(u.currentTarget)}},"Change color of selected items"),e.createElement(E,{onClick:()=>{l(y([...s],t))},disabled:!t.length},e.createElement(A,null),o?"Move selected items up":null),e.createElement(E,{onClick:()=>{l(D([...s],t))},disabled:!t.length},e.createElement(O,null),o?"Move selected items down":null),e.createElement(E,{onClick:()=>{l(y([...s],t,s.length))},disabled:!t.length},e.createElement(j,null),o?"Move selected items to top":null),e.createElement(E,{onClick:()=>{l(D([...s],t,s.length))},disabled:!t.length},e.createElement(_,null),o?"Move selected items to bottom":null),e.createElement(q.ColorPopover,{anchorEl:a,color:n,onChange:u=>{c(u),t.forEach(m=>{const h=s.find(i=>i.name===m);h&&(h.color=u)}),l([...s])},onClose:()=>{r(null)}}))}const ne=S()({textAreaFont:{fontFamily:"Courier New"}});function le({setCurrLayout:t,currLayout:l}){const{classes:s}=ne(),[o,a]=g.useState(""),[r,n]=g.useState();return e.createElement("div",null,e.createElement(L,null,'Paste CSV or TSV. If a header column is present. First line is a header. If a column called "name" is present, it uses that to connect to IDs in the table, otherwise it uses the first column no.'),e.createElement(U,{variant:"outlined",multiline:!0,minRows:5,placeholder:`name,population
HG00098,GBR
HG00101,GBR
HG00459,CHS
...`,maxRows:10,fullWidth:!0,value:o,onChange:c=>{a(c.target.value)},slotProps:{input:{classes:{input:s.textAreaFont}}}}),e.createElement(E,{variant:"contained",onClick:()=>{const c=o.split(`
`).map(m=>m.trim()).filter(m=>!!m),u=c[0].split(/[,\t]/gm);if(u.includes("name")){n("");const m=l.map(i=>[i.name,i]),h=Object.fromEntries(c.slice(1).map(i=>{const d=i.split(/[,\t]/gm),p=Object.fromEntries(d.map((b,f)=>[u[f],b]));return[p.name,{...p,...m[p.name]}]}));t(l.map(i=>({...i,...h[i.name]})))}else n(new Error('No "name" column found on line 1'))}},"Update rows"),e.createElement(E,{variant:"contained",onClick:()=>{const c=o.split(`
`).map(m=>m.trim()).filter(m=>!!m),u=c[0].split(/[,\t]/gm);if(u.includes("name")){n("");const m=l.map(i=>[i.name,i]),h=Object.fromEntries(c.slice(1).map(i=>{const d=i.split(/[,\t]/gm),p=Object.fromEntries(d.map((b,f)=>[u[f],b]));return[p.name,{...p,...m[p.name]}]}));t(l.map(i=>({...h[i.name]})))}else n(new Error('No "name" column found on line 1'))}},"Replace rows"),r?e.createElement(M.ErrorMessage,{error:r}):null)}function oe({setCurrLayout:t,currLayout:l}){var s;return e.createElement("div",null,Object.keys((s=l[0])!==null&&s!==void 0?s:[]).filter(o=>o!=="name"&&o!=="color").map(o=>e.createElement(E,{key:o,onClick:()=>{const a=new Map;for(const n of l){const c=a.get(n[o]);c?a.set(n[o],c+1):a.set(n[o],1)}const r=Object.fromEntries([...a.entries()].sort((n,c)=>n[1]-c[1]).map((n,c)=>[n[0],W.set1[c]||K(n[0])]));t(l.map(n=>({...n,color:r[n[o]]})))}},"Palettize ",o)))}const ae=S()({content:{minWidth:800},fr:{float:"right"},textAreaFont:{fontFamily:"Courier New"}});function me({model:t,handleClose:l}){const{classes:s}=ae(),{sources:o}=t,[a,r]=g.useState(!1),[n,c]=g.useState(o||[]),[u,m]=C.useLocalStorage("multivariant-showTips",!1);return e.createElement(X,{open:!0,onClose:l,maxWidth:"xl",title:"Multi-variant color/arrangement editor"},e.createElement($,{className:s.content},e.createElement("div",{className:s.fr},e.createElement(E,{variant:"contained",onClick:()=>{m(!u)}},u?"Hide tips":"Show tips"),e.createElement(E,{color:"secondary",variant:"contained",onClick:()=>{r(!a)}},a?"Hide bulk row editor":"Show Bulk row editor")),e.createElement("br",null),u?e.createElement(re,null):null,a?e.createElement(le,{currLayout:n,setCurrLayout:c}):null,e.createElement(oe,{currLayout:n,setCurrLayout:c}),e.createElement(ee,{rows:n,onChange:c,showTips:u})),e.createElement(z,null,e.createElement(E,{variant:"contained",type:"submit",color:"inherit",onClick:()=>{t.clearLayout(),c(t.sources||[])}},"Clear custom settings"),e.createElement(E,{variant:"contained",color:"secondary",onClick:()=>{l(),c([...t.sources||[]])}},"Cancel"),e.createElement(E,{variant:"contained",color:"primary",type:"submit",onClick:()=>{t.setLayout(n),l()}},"Submit")))}function re(){return e.createElement(e.Fragment,null,"Helpful tips",e.createElement("ul",null,e.createElement("li",null,"You can select rows in the table with the checkboxes"),e.createElement("li",null,"Multi-select is enabled with shift-click and control-click"),e.createElement("li",null,'The "Move selected items up/down" can re-arrange subtracks'),e.createElement("li",null,"Sorting the data grid itself can also re-arrange subtracks"),e.createElement("li",null,"Changes are applied when you hit Submit"),e.createElement("li",null,"You can click and drag the dialog box to move it on the screen"),e.createElement("li",null,"Columns in the table can be hidden using a vertical '...' menu on the right side of each column")))}export{me as default};
