import{B as e,C as t,K as n,O as r,S as i,St as a,T as o,Y as s,ct as c,dt as l,f as u,ft as d,j as f,k as p,kt as m,nn as h,q as g,w as _,x as v}from"./vue.runtime.esm-bundler-DpGzKKN4.js";import"./GxPagination-DOexUzbO.js";import{Ot as y,m as b}from"./vnode-DU8g6Rf7.js";import{t as x}from"./alert-0-u4BC19.js";import{t as S}from"./button-CHjzS7b0.js";import{t as C}from"./_plugin-vue_export-helper-CnS4QQza.js";import{a as w,o as ee}from"./GxDialog-BUqY5Fq3.js";import{Da as T,Hi as E,Vi as D,vt as O}from"./stores-BWYw2E2w.js";import"./css-DunA3L7q.js";var k={class:`panel-content`},A={class:`xml-test-tab px-3 py-2 flex flex-col gap-2`},j={class:`flex items-center justify-between`},M={class:`flex flex-wrap gap-2`},N=C(f({__name:`XmlTestFloatingPanel`,props:{activeFormUuid:{},getOpenedTabFormObjItem:{type:Function},afterApplyXml:{type:Function}},setup(f){let C=new Map([[`_gx-mobile-navbar-button`,`gx-mobile-navbar-button`],[`_gx-mobile-navbar-dropdown`,`gx-mobile-navbar-dropdown`]]),N=new Map(Array.from(C.entries()).map(([e,t])=>[t,e])),P=f,F=E(),I=O(),L=D(),R=a(!1),z=()=>{R.value=!R.value},B=a(``),V=a(``),H=a(null),U=v(()=>P.getOpenedTabFormObjItem?P.activeFormUuid||``:P.activeFormUuid||F.activeDesignTabsValue||``);function W(e){return P.getOpenedTabFormObjItem?P.getOpenedTabFormObjItem(e):F.getOpenedTabFormObjItem(e)}function G(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function K(e){if(Array.isArray(e))return e.map(e=>K(e));if(!G(e))return e;let t={};return Object.entries(e).forEach(([e,n])=>{let r=C.get(e);t[r&&G(n)?r:e]=K(n)}),t}function q(e){let t=e?.form?.body?.[`gx-mobile-root`];return(Array.isArray(t)?t:t?[t]:[]).forEach(e=>{G(e)&&N.forEach((t,n)=>{e[n]==null||e[t]!=null||(e[t]=e[n],delete e[n])})}),e}function J(){if(!U.value)return null;let e=W(U.value)?.rawXmlObj;if(!e)return null;try{let t=T,n=K(e),r=t.js2xml_str?.(n)??t.js2xml?.(n);return typeof r==`string`?r:null}catch{return null}}function Y(){let e=J();e!=null&&(B.value=e)}async function X(e){let t=U.value;if(!t)return Promise.reject(Error(`当前无打开的设计页`));let n;try{n=T.xml2js(e)}catch(e){return Promise.reject(e)}if(n=q(n),!n?.form?.body)return Promise.reject(Error(`XML 结构无效，需包含 form.body`));I.tempFormPool.add(`form`,t,n);let r=W(t)?.flushLocalXmlObj;if(typeof r!=`function`)return Promise.reject(Error(`当前设计页尚未就绪`));await r();let i=W(t);await P.afterApplyXml?.({activeFormUuid:t,xmlObj:n,openedTab:i})}let Z=()=>{V.value=``;let e=(B.value||``).trim();if(!e){V.value=`请输入或粘贴 XML`;return}H.value=J(),X(e).catch(e=>{V.value=e instanceof Error?e.message:String(e)})},Q=v(()=>!!H.value),te=()=>{let e=H.value;e&&(V.value=``,B.value=e,H.value=null,X(e).catch(e=>{V.value=`回退渲染失败：${e instanceof Error?e.message:String(e)}`}))},$=t=>{t?.localFormUuid===U.value&&e(Y)};return c(U,()=>{e(Y)},{immediate:!0}),n(()=>{F.setXmlTestTabActive(!0),L.emitter.on(`design-main-form-updated`,$)}),g(()=>{F.setXmlTestTabActive(!1),L.emitter.off(`design-main-form-updated`,$)}),(e,n)=>{let a=y,c=S,f=b,g=x;return s(),o(`div`,{class:h([`xml-test-floating-panel`,{"is-collapsed":R.value}])},[d(i(`div`,{class:`expand-tab`,onClick:z,title:`展开`},[p(a,null,{default:l(()=>[p(m(ee))]),_:1})],512),[[u,R.value]]),d(i(`div`,k,[i(`div`,A,[i(`div`,j,[n[1]||=i(`span`,{class:`text-sm text-gray-600`},`与当前设计区 XML 双向同步；应用后直接渲染（不保存到后端）。`,-1),p(c,{text:``,size:`small`,class:`shrink-btn`,onClick:z,title:`收缩`},{default:l(()=>[p(a,null,{default:l(()=>[p(m(w))]),_:1})]),_:1})]),p(f,{modelValue:B.value,"onUpdate:modelValue":n[0]||=e=>B.value=e,type:`textarea`,rows:12,placeholder:`粘贴表单 XML…`,class:`font-mono text-xs`},null,8,[`modelValue`]),i(`div`,M,[p(c,{type:`primary`,class:`apply-xml-btn`,onClick:Z},{default:l(()=>[...n[2]||=[r(`应用`,-1)]]),_:1}),p(c,{disabled:!Q.value,onClick:te},{default:l(()=>[...n[3]||=[r(`回退`,-1)]]),_:1},8,[`disabled`])]),V.value?(s(),t(g,{key:0,type:`error`,title:V.value,"show-icon":``,class:`!py-2`},null,8,[`title`])):_(``,!0)])],512),[[u,!R.value]])],2)}}}),[[`__scopeId`,`data-v-35effd01`]]);export{N as t};