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