import{A as B,r,j as e,B as o,b6 as S,bX as T,bY as N,aq as O,d as k}from"./utils.js";import{b as v,a as h,r as z,c as U}from"./lowCodeApi.js";import{L as E}from"./LowCode2.js";import{F as y,D as g,u as q}from"./index5.js";import{g as D}from"./zh_CN.js";import{d as L,E as H,e as J}from"./logger.js";import{D as V,a6 as R,a7 as j,a4 as W,P as _,R as b,a3 as Q,O as X,L as G,Q as K,$ as Z,a1 as ee,F as se}from"./SaveOutlined.js";import{R as ie}from"./FormOutlined.js";import{d as te}from"./preload-helper.js";import"./index2.js";const ae={labelCol:{span:5},wrapperCol:{span:19}},ne=({dialogStatus:a,dismissDialog:i,refreshTableData:t,currentItem:c})=>{const{message:l}=B.useApp(),[x]=y.useForm(),w=r.useMemo(()=>a===g.VIEW,[a]),d=r.useCallback(async m=>{if(a===g.ADD)try{const u=await v(m.name);await h({...m,id:D(),jsonSchema:JSON.stringify(u),isBuiltIn:!1}),l.success("新增页面成功"),i(),t==null||t()}catch{l.error("新增页面失败")}else if(a===g.EDIT)try{await h({...c,...m}),l.success("编辑页面基础信息成功"),i(),t==null||t()}catch{l.error("编辑页面基础信息失败")}},[c,a]),I=r.useMemo(()=>c?{...c}:{name:"",desc:""},[c]);return e.jsx(V,{size:"large",title:`${a}页面`,open:!0,onClose:i,extra:e.jsxs(j,{children:[e.jsx(o,{size:"large",onClick:i,children:"取消"}),a!==g.VIEW&&e.jsx(o,{icon:e.jsx(W,{}),type:"primary",size:"large",onClick:x.submit,children:"保存"})]}),children:e.jsxs(y,{...ae,form:x,onFinish:d,initialValues:I,disabled:w,children:[e.jsx(y.Item,{label:"页面名称",name:"name",rules:[{required:!0,max:15,message:"请输入页面名称，最大长度为 15"}],children:e.jsx(R,{placeholder:"请输入页面名称，最大长度为 15"})}),e.jsx(y.Item,{label:"页面描述",name:"desc",rules:[{required:!0,max:30,message:"请输入页面描述，最大长度为 30"}],children:e.jsx(R.TextArea,{placeholder:"请输入页面描述，最大长度为 30"})})]})})},P=async(a,i)=>{let t=`lowcode.html?lowCodeType=${a}&pageId=${i.id}`;if(O("devWeb")==="1"&&(t+="&devWeb=1"),J){t=await chrome.runtime.getURL(t),await chrome.tabs.create({url:t});return}t=await k.chrome.runtime.getURL(t),await k.chrome.tabs.create({url:t})},ge=()=>{r.useEffect(()=>{S()},[]);const{modal:a,message:i}=B.useApp(),[t,c]=r.useState(!1),{currentItem:l,dialogStatus:x,refreshTableCondition:w,refreshTableData:d,showAddDialog:I,dismissEditDialog:m,showEditDialog:u}=q(),[Y,A]=r.useState([]),C=r.useCallback(async()=>{try{c(!0);const f=await z();A(f)}catch{i.error("请求页面列表失败")}finally{c(!1)}},[]);r.useEffect(()=>{C()},[w]);const F=r.useMemo(()=>[{width:174,align:"center",title:"页面 ID",dataIndex:"id",key:"id"},{align:"center",title:"页面名称",dataIndex:"name",key:"name"},{align:"center",title:"描述",dataIndex:"desc",key:"desc"},{width:175,align:"center",title:"更新时间",dataIndex:"updateTime",key:"updateTime",render:f=>L(f).format("YYYY-MM-DD HH:mm:ss")},{width:320,align:"center",title:"操作",render:(f,s,$)=>e.jsxs(j,{direction:"vertical",children:[e.jsxs(j,{children:[e.jsx(_,{icon:e.jsx(Q,{style:{color:"red"}}),title:"确认删除该页面吗？",onConfirm:async()=>{try{await U(s.id),i.success("删除页面成功"),d()}catch{i.error("删除页面失败")}},okText:"确认删除",cancelText:"取消",okButtonProps:{icon:e.jsx(b,{})},okType:"danger",disabled:s.isBuiltIn,children:e.jsx(o,{danger:!0,icon:e.jsx(b,{}),disabled:s.isBuiltIn,children:"删除"})}),e.jsx(o,{type:"dashed",icon:e.jsx(ie,{}),onClick:()=>u(s,$),children:"编辑基础信息"}),e.jsx(o,{icon:e.jsx(te,{}),type:"primary",onClick:()=>P(E.Preview,s),children:"查看页面"}),e.jsx(o,{type:"primary",icon:e.jsx(X,{}),onClick:()=>P(E.Editor,s),children:"编辑页面"})]}),e.jsxs(j,{children:[e.jsx(o,{icon:e.jsx(G,{}),onClick:async()=>{try{const p={...s,name:`${s.name}-副本`,desc:`${s.desc}-副本`,id:D(),isBuiltIn:!1};await h(p),i.success("复制页面成功"),d(),u(p,$)}catch{i.error("复制页面失败")}},children:"复制页面"}),e.jsx(o,{icon:e.jsx(K,{}),onClick:()=>{T(JSON.stringify(s),`${H}导出页面-${s.id}-${s.name}-${L().format("YYYYMMDD_HHmmss")}.json`)},children:"导出页面到文件"}),e.jsx(o,{icon:e.jsx(Z,{}),onClick:async()=>{const{canceled:p,result:n}=await N();if(!p){if(!n||!n.id||!n.name||!n.desc||!n.updateTime||!n.jsonSchema){i.error("从文件导入的内容格式错误");return}if(n.id===s.id)try{await h({...n,isBuiltIn:s.isBuiltIn}),i.success("从文件导入页面成功"),d()}catch{i.error("从文件导入页面失败")}else a.confirm({title:`从文件导入页面「${n.name}」的 id「${n.id}」和当前选中的页面「${s.name}」的 id「${s.id}」不同，确认导入除 id 以外的页面信息吗？`,okText:"确认",onOk:async()=>{try{await h({...n,id:s.id,isBuiltIn:s.isBuiltIn}),i.success("从文件导入页面成功"),C()}catch{i.error("从文件导入页面失败")}}})}},children:"从文件导入页面"})]})]})}],[]);return e.jsxs("div",{style:{padding:20},children:[e.jsx(j,{style:{display:"flex",justifyContent:"end"},children:e.jsx(o,{icon:e.jsx(ee,{}),type:"primary",size:"large",onClick:()=>I(),children:"新增页面"})}),e.jsx(se,{style:{marginTop:20,height:"100%"},bordered:!0,rowKey:"id",pagination:{pageSize:20},loading:t,columns:F,dataSource:Y}),x!==g.GONE&&e.jsx(ne,{dialogStatus:x,dismissDialog:m,currentItem:l,refreshTableData:d})]})};export{ge as default};
