import{I as r}from"./iconify-p99pbjf9.js";import{d as I,aa as N,r as w,w as P,o as _,g,A as z,B as i,C as o,j as e,an as u,ax as c,t as l,i as C,_ as y,P as h,O as $,aw as R,K as V,c as k,a as M}from"./index-DOFLUERq.js";import U from"./SchemaEditorModal-Dx35HFmL.js";import{_ as j}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./_commonjsHelpers-CE1G-McA.js";const x=I({__name:"ai_node_toolbar",props:{entity:{},id:{},record:{default:()=>({})},canEdit:{type:Boolean},loading:{type:Boolean},sidebarPosition:{default:"left"}},emits:["toggle-sidebar-position","refresh","delete","go-back","save"],setup(d,{emit:A}){const n=d,b=N(),f=k(()=>{const a=n.id;return a==="new"||a.startsWith("new-")}),m=w(!1),S=k(()=>String(n.id)),p=k(()=>n.record||{});function B(){if(!f.value){if(!p.value.node_type){b.warning(l("Please select node type first"));return}m.value=!0}}async function E(a){try{const t=await M.put(`/api/data/${encodeURIComponent(n.entity)}/${encodeURIComponent(S.value)}`,{node_schema:a});if(t.data?.success!==!1)n.record&&(n.record.node_schema=a),b.success(l("Schema saved successfully")),m.value=!1;else throw new Error(t.data?.message||l("Save failed"))}catch(t){throw console.error("保存 Schema 失败:",t),b.error(t?.response?.data?.message||t?.message||l("Save failed, please check permission and server logs")),t}}const v=w(n.sidebarPosition||"left");return P(()=>n.sidebarPosition,a=>{a&&(v.value=a)},{immediate:!0}),_(()=>{if(!n.sidebarPosition){const a=localStorage.getItem("jingrow-sidebar-position");(a==="left"||a==="right")&&(v.value=a)}}),(a,t)=>(g(),z(V,null,[i(e(R),{align:"center"},{default:o(()=>[i(e(u),{type:"default",size:"medium",onClick:t[0]||(t[0]=s=>a.$emit("toggle-sidebar-position")),title:v.value==="left"?"切换到右侧":"切换到左侧",class:"header-action-btn"},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:v.value==="left"?"fluent:panel-right-16-regular":"fluent:panel-left-16-regular"},null,8,["icon"])]),_:1})]),_:1},8,["title"]),i(e(u),{type:"default",size:"medium",onClick:t[1]||(t[1]=s=>a.$emit("refresh")),disabled:d.loading||f.value,title:e(l)("Refresh"),class:"header-action-btn"},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:"tabler:refresh"})]),_:1})]),_:1},8,["disabled","title"]),i(e(u),{type:"default",size:"medium",onClick:t[2]||(t[2]=s=>a.$emit("delete")),disabled:d.loading||f.value,title:e(l)("Delete"),class:"header-action-btn delete-btn"},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:"tabler:trash"})]),_:1})]),_:1},8,["disabled","title"]),f.value?$("",!0):(g(),C(e(u),{key:0,type:"default",size:"medium",onClick:B,class:"toolbar-btn schema-editor-btn"},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:"tabler:edit"})]),_:1})]),default:o(()=>[y(" "+h(e(l)("Edit Schema")),1)]),_:1})),i(e(u),{type:"default",size:"medium",onClick:t[3]||(t[3]=s=>a.$emit("go-back")),disabled:d.loading},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:"tabler:arrow-left"})]),_:1})]),default:o(()=>[y(" "+h(e(l)("Back")),1)]),_:1},8,["disabled"]),d.canEdit?(g(),C(e(u),{key:1,type:"primary",size:"medium",disabled:d.loading,onClick:t[4]||(t[4]=s=>a.$emit("save")),class:"save-btn-brand"},{icon:o(()=>[i(e(c),null,{default:o(()=>[i(e(r),{icon:"tabler:check"})]),_:1})]),default:o(()=>[y(" "+h(e(l)("Save")),1)]),_:1},8,["disabled"])):$("",!0)]),_:1}),i(U,{visible:m.value,"onUpdate:visible":t[5]||(t[5]=s=>m.value=s),"node-type":p.value.node_type||"","node-name":S.value,"initial-schema":p.value.node_schema||{},"on-save":E,onClose:t[6]||(t[6]=s=>m.value=!1)},null,8,["visible","node-type","node-name","initial-schema"])],64))}}),W=j(x,[["__scopeId","data-v-7280f4c0"]]);export{W as default};
