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