import{d as N,c as l,u as V,r as D,e as J,f as c,C as v,j as m,J as O,h as P,aP as T,B as j,K as b,a7 as x,t as s,n as C}from"./index-a0da86f0.js";import z from"./SchemaEditorModal-b897dd40.js";import{_ as F}from"./_plugin-vue_export-helper-c27b6911.js";import"./_commonjsHelpers-de833af9.js";const K=["title"],q=["title"],A=["title","disabled"],G=["title"],H=N({__name:"local_ai_node_list_actions",props:{context:{},row:{},entity:{},viewMode:{}},emits:["view","edit","delete"],setup(S,{emit:g}){const n=S,f=g,a=l(()=>{var e;return n.row||((e=n.context)==null?void 0:e.row)}),_=l(()=>{var e;return n.entity||((e=n.context)==null?void 0:e.entity)}),E=l(()=>{var e;return n.viewMode||((e=n.context)==null?void 0:e.viewMode)||"list"}),k=l(()=>E.value==="card"?"actions-container card-actions":"actions-container col-actions"),u=V(),d=D(!1),p=l(()=>{var e;return((e=a.value)==null?void 0:e.name)||""}),h=l(()=>{var e;return((e=a.value)==null?void 0:e.node_type)||""}),R=l(()=>{var t;const e=(t=a.value)==null?void 0:t.node_schema;if(!e)return{};if(typeof e=="string")try{return JSON.parse(e)}catch{return{}}return e}),w=l(()=>!!h.value);function M(){var e;(e=n.context)!=null&&e.openDetail?n.context.openDetail(a.value.name):f("view",a.value)}function B(){var e;(e=n.context)!=null&&e.editRecord?n.context.editRecord(a.value):f("edit",a.value)}function I(){var e;(e=n.context)!=null&&e.deleteRecord?n.context.deleteRecord(a.value.name):f("delete",a.value)}async function U(){var e,t;if(!w.value){u.warning(s("Please select node type first"));return}if(!((e=a.value)!=null&&e.node_schema))try{const r=((t=(await b.get(`/api/data/${encodeURIComponent(_.value)}/${encodeURIComponent(p.value)}`,{headers:x(),withCredentials:!0})).data)==null?void 0:t.data)||{};r.node_schema&&a.value&&(a.value.node_schema=r.node_schema)}catch(i){console.error("获取节点数据失败:",i),u.error(s("Failed to load node data"));return}d.value=!0}async function $(e){var t,i,r,y;try{const o=await b.put(`/api/data/${encodeURIComponent(_.value)}/${encodeURIComponent(p.value)}`,{node_schema:e},{headers:x(),withCredentials:!0});if(((t=o.data)==null?void 0:t.success)!==!1)a.value&&(a.value.node_schema=e),u.success(s("Schema saved successfully")),d.value=!1;else throw new Error(((i=o.data)==null?void 0:i.message)||s("Save failed"))}catch(o){throw console.error("保存 Schema 失败:",o),u.error(((y=(r=o==null?void 0:o.response)==null?void 0:r.data)==null?void 0:y.message)||(o==null?void 0:o.message)||s("Save failed, please check permission and server logs")),o}}return(e,t)=>(C(),J("div",{class:j(k.value)},[c("button",{class:"action-btn",onClick:v(M,["stop"]),title:m(s)("View")},[...t[2]||(t[2]=[c("i",{class:"fa fa-eye"},null,-1)])],8,K),c("button",{class:"action-btn",onClick:v(B,["stop"]),title:m(s)("Edit")},[...t[3]||(t[3]=[c("i",{class:"fa fa-edit"},null,-1)])],8,q),c("button",{class:"action-btn schema-btn",onClick:v(U,["stop"]),title:m(s)("Edit Schema"),disabled:!w.value},[...t[4]||(t[4]=[c("i",{class:"fa fa-table"},null,-1)])],8,A),c("button",{class:"action-btn delete-btn",onClick:v(I,["stop"]),title:m(s)("Delete")},[...t[5]||(t[5]=[c("i",{class:"fa fa-trash"},null,-1)])],8,G),(C(),O(T,{to:"body"},[P(z,{visible:d.value,"onUpdate:visible":t[0]||(t[0]=i=>d.value=i),"node-type":h.value,"node-name":p.value,"initial-schema":R.value,"on-save":$,onClose:t[1]||(t[1]=i=>d.value=!1)},null,8,["visible","node-type","node-name","initial-schema"])]))],2))}});const Y=F(H,[["__scopeId","data-v-f7c363f2"]]);export{Y as default};
