import{ah as L,g as u,A as f,J as p,K as h,L as y,H as D,j as l,B as _,t as b,a8 as V,O as $,P as w,G as A}from"./index-DOFLUERq.js";import{u as B}from"./store-7aRonVWq.js";import O from"./EditableInput-DQlgWBJl.js";import P from"./SchemaSections-BAEJPWaR.js";import{_ as W}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./vuedraggable.umd-CrsnNXKf.js";import"./_commonjsHelpers-CE1G-McA.js";const j={class:"schema-tabs"},F={class:"tab-header"},z={class:"tabs"},J=["onClick","onDragstart","onDragover","onDrop"],U=["onClick"],G={class:"tab-actions"},H=["title"],K={__name:"SchemaTabs",setup(M){const o=B(),v=L();let r={isDragging:!1,draggedTabId:null,dragStartTime:0};function I(){o.addTab()}function k(a){const i=a.sections.reduce((t,e)=>t+e.columns.reduce((s,c)=>s+c.fields.length,0),0);if(i===0){o.removeTab(a.id);return}v.error({title:"确认删除",content:`确定要删除标签页 "${a.label}" 吗？这将同时删除标签页内的 ${i} 个字段，此操作不可恢复。`,positiveText:"删除",negativeText:"取消",onPositiveClick:()=>{a.sections.forEach(t=>{t.columns.forEach(e=>{e.fields.forEach(s=>{o.removeProperty(s)})})}),o.removeTab(a.id),o.markDirty()}})}function T(a){o.activateTab(a.id)}function x(a,i){a.dataTransfer.setData("text/plain",i.id),a.dataTransfer.effectAllowed="move",a.target.classList.add("dragging"),r.isDragging=!0,r.draggedTabId=i.id,r.dragStartTime=Date.now()}function S(a){a.target.classList.remove("dragging"),r.isDragging=!1,r.draggedTabId=null,r.dragStartTime=0}function C(a,i){if(r.isDragging&&r.draggedTabId&&r.draggedTabId.startsWith("tab_")){a.preventDefault(),a.dataTransfer.dropEffect="move";return}(a.dataTransfer.types.includes("application/json")||a.dataTransfer.types.includes("text/plain")&&!r.draggedTabId?.startsWith("tab_"))&&o.layout.activeTab!==i.id&&T(i)}function E(a,i){a.preventDefault();const t=a.dataTransfer.getData("text/plain");if(t&&t.startsWith("tab_")&&t!==i.id){const s=o.layout.tabs,c=s.findIndex(n=>n.id===t),d=s.findIndex(n=>n.id===i.id);if(c!==-1&&d!==-1){const n=s.splice(c,1)[0];s.splice(d,0,n),o.markDirty()}return}try{const s=JSON.parse(a.dataTransfer.getData("application/json"));if(s.type==="field"){N(s);return}}catch{}const e=a.dataTransfer.getData("text/plain");e&&!e.startsWith("tab_")&&o.addPropertyToTab(o.layout.activeTab,e)}function N(a){const{fieldId:i,sourceColumnId:t,sourceSectionId:e,sourceTabId:s}=a;if(t&&e&&s){const d=o.layout.tabs.find(n=>n.id===s);if(d){const n=d.sections.find(g=>g.id===e);if(n){const g=n.columns.find(m=>m.id===t);if(g){const m=g.fields.indexOf(i);m>-1&&g.fields.splice(m,1)}}}}const c=o.layout.tabs.find(d=>d.id===o.layout.activeTab);if(c&&c.sections.length>0){const d=c.sections[0];if(d.columns.length>0){const n=d.columns[0];n.fields.includes(i)||n.fields.push(i)}}o.markDirty()}return(a,i)=>(u(),f("div",j,[p("div",F,[p("div",z,[(u(!0),f(h,null,y(l(o).layout.tabs,t=>(u(),f("div",{key:t.id,class:D(["tab",l(o).layout.activeTab===t.id?"active":""]),draggable:!0,onClick:e=>T(t),onDragstart:e=>x(e,t),onDragend:i[0]||(i[0]=e=>S(e)),onDragover:e=>C(e,t),onDrop:e=>E(e,t)},[_(O,{text:t.label,placeholder:l(b)("Tab Name"),"onUpdate:modelValue":e=>l(o).updateTabLabel(t.id,e),onClick:e=>T(t)},null,8,["text","placeholder","onUpdate:modelValue","onClick"]),l(o).layout.tabs.length>1?(u(),f("button",{key:0,class:"remove-tab-btn",onClick:V(e=>k(t),["stop"]),title:"删除标签页"}," × ",8,U)):$("",!0)],42,J))),128))]),p("div",G,[p("button",{class:"add-tab-btn",onClick:I,title:l(b)("Add Tab")}," + "+w(l(b)("Add Tab")),9,H)])]),(u(!0),f(h,null,y(l(o).layout.tabs,t=>(u(),f("div",{key:t.id,class:D(["tab-content-area",{active:l(o).layout.activeTab===t.id}]),style:A({display:l(o).layout.activeTab===t.id?"block":"none"})},[_(P,{tab:t},null,8,["tab"])],6))),128))]))}},at=W(K,[["__scopeId","data-v-68b72cd1"]]);export{at as default};
