import{i as e,t}from"./react-B8IZ02wI.js";import{n}from"./table-BvNKB5G4.js";import{t as r}from"./checkbox-C6Bqqig-.js";import{n as i,st as a}from"./index-Bg7bo8aA.js";var o=e(t(),1),s=i();function c({open:e,metas:t,order:i,visible:c,onClose:l,onSave:u}){let[d,f]=(0,o.useState)(i),[p,m]=(0,o.useState)(new Set(c)),[h,g]=(0,o.useState)(null),[_,v]=(0,o.useState)(null);(0,o.useEffect)(()=>{e&&(f(i),m(new Set(c)),g(null),v(null))},[e,i,c]);let y=Object.fromEntries(t.map(e=>[e.key,e.title])),b=(e,t)=>{let n=new Set(p);t?n.add(e):n.delete(e),m(n)},x=(e,t)=>{if(e===t)return;let n=[...d],r=n.indexOf(e),i=n.indexOf(t);r<0||i<0||(n.splice(r,1),n.splice(i,0,e),f(n))};return(0,s.jsxs)(a,{title:`列设置`,open:e,onCancel:l,onOk:()=>u(d,[...p]),okText:`保存`,width:440,destroyOnHidden:!0,children:[(0,s.jsx)(`p`,{style:{fontSize:12,color:`#6b7280`,marginBottom:12},children:`勾选要显示的列，按住左侧手柄拖拽调整顺序（序号与操作列固定）`}),(0,s.jsx)(`div`,{className:`list-col-settings`,children:d.map(e=>(0,s.jsxs)(`div`,{className:`list-col-settings-row${h===e?` is-dragging`:``}${_===e&&h&&h!==e?` is-over`:``}`,draggable:!0,onDragStart:t=>{g(e),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e)},onDragEnd:()=>{g(null),v(null)},onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect=`move`,_!==e&&v(e)},onDragLeave:()=>{_===e&&v(null)},onDrop:t=>{t.preventDefault();let n=t.dataTransfer.getData(`text/plain`)||h;n&&x(n,e),g(null),v(null)},children:[(0,s.jsx)(`span`,{className:`list-col-settings-handle`,title:`拖拽排序`,"aria-hidden":!0,children:(0,s.jsx)(n,{})}),(0,s.jsx)(r,{checked:p.has(e),onChange:t=>b(e,t.target.checked),onClick:e=>e.stopPropagation(),children:y[e]||e})]},e))})]})}function l(e){return e.map(e=>e.key)}function u(e){return e.filter(e=>e.defaultVisible!==!1).map(e=>e.key)}function d(e,t){let n=new Set(t.map(e=>e.key));try{let r=localStorage.getItem(e);if(r){let e=JSON.parse(r),i=e.order||[],a=e.visible||[],o=new Set(i),s=i.filter(e=>n.has(e)),c=a.filter(e=>n.has(e));for(let e of t)s.includes(e.key)||(s.push(e.key),e.defaultVisible!==!1&&!o.has(e.key)&&!c.includes(e.key)&&c.push(e.key));if(c.length)return{order:s,visible:c}}}catch{}return{order:l(t),visible:u(t)}}function f(e,t){let[n,r]=(0,o.useState)(()=>d(e,t)),[i,a]=(0,o.useState)(!1),s=(0,o.useMemo)(()=>new Set(n.visible),[n.visible]);return{metas:t,orderedVisibleKeys:(0,o.useMemo)(()=>n.order.filter(e=>s.has(e)),[n.order,s]),visibleSet:s,open:i,setOpen:a,save:(t,n)=>{let i={order:t,visible:n};r(i),localStorage.setItem(e,JSON.stringify(i)),a(!1)},currentOrder:n.order,currentVisible:n.visible}}export{c as n,f as t};