const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/timeline-CIH67oDr.js","assets/index-DOFLUERq.js","assets/index-Cl-AM8AM.css","assets/common-DEIQtiPI.js"])))=>i.map(i=>d[i]);
import{a as K,d as ue,b as ce,e as de,aa as fe,o as me,f as ve,w as pe,g as r,A as u,J as c,B as h,C as g,P as C,j as i,aw as A,an as M,_ as x,t as o,ax as L,i as U,O as R,K as T,L as B,H as j,a6 as ge,ab as he,u as ye,a_ as _e,r as y,c as N,a0 as be}from"./index-DOFLUERq.js";import ke from"./FieldRenderer-B93hvLtQ.js";import{I as z}from"./iconify-p99pbjf9.js";import{getPageTypeMeta as we,api as Se}from"./common-DEIQtiPI.js";import{e as Ce,l as Fe}from"./timeline-CIH67oDr.js";import{_ as De}from"./_plugin-vue_export-helper-DlAUqK2U.js";async function Te(_){try{const f=`/api/data/${encodeURIComponent(_)}/${encodeURIComponent(_)}`,m=await K.get(f);return m.data?.data?{success:!0,data:m.data.data}:{success:!0,data:{}}}catch(f){return console.error("Failed to get single page data:",f),{success:!1,message:f.response?.data?.detail||f.message||"获取单页数据失败"}}}async function Be(_,f){try{const m=`/api/data/${encodeURIComponent(_)}/${encodeURIComponent(_)}`;return await K.put(m,f),{success:!0}}catch(m){return console.error("Failed to save single page data:",m),{success:!1,message:m.response?.data?.detail||m.message||"保存单页数据失败"}}}const Oe={class:"single-page-detail"},Ee={class:"page-header"},Ne={class:"page-title"},$e={class:"page-description"},Je={class:"form-layout"},Pe={class:"form-page"},Re={key:0,class:"form-tabs-list"},Ie={class:"nav form-tabs"},Ve=["onClick"],Ae={class:"form-tab-content"},Me={class:"form-sections"},xe={key:0,class:"section-header"},Le={class:"section-body"},Ue=ue({__name:"default_single",setup(_){const f=ce(),m=de(),b=fe(),{entity:v}=ye(f),$=_e(()=>v.value),O=y(!1),l=y({}),F=y([]),k=y({}),D=y("default"),w=y(!1),W=Ce(v.value,l),q=N(()=>l.value.name||l.value.label||o(v.value)),H=N(()=>""),S=N(()=>{const e=G(),s=[];let t=null,a=null,n=null;e.some(d=>d.fieldtype==="Tab Break")||(t={key:"default",label:o("Detail"),sections:[]});for(const d of e)switch(d.fieldtype){case"Tab Break":t&&(a&&(n&&n.fields.length>0&&(a.columns||(a.columns=[]),a.columns.push({...n})),a.columns&&a.columns.length>0&&(t.sections||(t.sections=[]),t.sections.push({...a}))),t.sections&&t.sections.length>0&&s.push({...t})),t={key:d.fieldname||d.label||`tab_${s.length+1}`,label:d.label||d.fieldname||o("Detail"),sections:[]},a=null,n=null;break;case"Section Break":a&&(n&&n.fields.length>0&&(a.columns||(a.columns=[]),a.columns.push({...n})),a.columns&&a.columns.length>0&&(t.sections||(t.sections=[]),t.sections.push({...a}))),a={key:d.fieldname||d.label||`section_${t?t.sections.length+1:1}`,label:d.label||"",columns:[]},n=null;break;case"Column Break":t||(t={key:"default",label:o("Detail"),sections:[]}),a||(a={key:"default",label:"",columns:[]}),n&&n.fields.length>0&&(a.columns||(a.columns=[]),a.columns.push({...n})),n={key:`column_${a.columns?a.columns.length:0}`,fields:[]};break;default:t||(t={key:"default",label:o("Detail"),sections:[]}),a||(a={key:"default",label:"",columns:[]}),n||(n={key:"default",fields:[]}),n.fields.push(d);break}return t&&(a&&(n&&n.fields.length>0&&(a.columns||(a.columns=[]),a.columns.push({...n})),a.columns&&a.columns.length>0&&(t.sections||(t.sections=[]),t.sections.push({...a}))),t.sections&&t.sections.length>0&&s.push({...t})),s}),Y=N(()=>S.value.length>1);function G(){const e=new Map;if(F.value.forEach(s=>{e.set(s.fieldname,s)}),k.value.field_order&&Array.isArray(k.value.field_order)){const s=k.value.field_order.filter(n=>e.has(n)).map(n=>e.get(n)),t=new Set(k.value.field_order),a=F.value.filter(n=>!t.has(n.fieldname));return[...s,...a]}return F.value}function Q(e){return e.sections||[]}const J=y({});function X(e){return J.value[e.fieldname]?J.value[e.fieldname].map(a=>({label:$(a),value:a})):e.options?e.options.split(`
`).filter(t=>t.trim()!=="").map(t=>({label:$(t),value:t})):[]}function Z(e){if(!e)return null;if(typeof e=="number")return e;if(e instanceof Date)return e.getTime();const s=new Date(e);return isNaN(s.getTime())?null:s.getTime()}function ee(e,s){if(s==null)l.value[e]=null;else{const t=new Date(s),a=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),p=String(t.getDate()).padStart(2,"0");l.value[e]=`${a}-${n}-${p}`}}function te(e){if(!e)return"";try{return JSON.stringify(e,null,2)}catch{return String(e)}}function ae(e){if(!e)return"";if(typeof e=="string")try{const s=JSON.parse(e);return JSON.stringify(s,null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return String(e)}}function se(e,s){if(!s.trim()){l.value[e]=null;return}try{l.value[e]=JSON.parse(s)}catch{l.value[e]=s}}function ne(e){}function le(e){if(!e)return!0;try{if(e.startsWith("eval:")){const s=e.substring(5),t=l.value;return!!new Function("pg",`return !!(${s})`)(t)}return!!l.value[e]}catch{return!e.startsWith("eval:")}}function I(e){return["Tab Break","Section Break","Column Break"].includes(e.fieldtype)}function ie(e){return I(e)||e&&(e.hidden===1||e.hidden===!0||e.hidden==="1")?!1:e.depends_on?le(e.depends_on):!0}async function E(){w.value=!0;try{const[e,s]=await Promise.all([we(v.value),Te(v.value)]),t=e.success&&e.data?e.data:{};t&&(F.value=t.fields||[],k.value=t||{},k.value.is_virtual?O.value=!1:O.value=!0),s.success?l.value=s.data||{}:(b.error(s.message||o("Failed to load data")),l.value={}),S.value.length>0&&(D.value=S.value[0].key),await oe()}catch(e){b.error(o("Failed to load data")),console.error("Failed to load data:",e),l.value={}}finally{w.value=!1}}async function oe(){const{triggerFieldConfig:e}=await be(async()=>{const{triggerFieldConfig:s}=await import("./timeline-CIH67oDr.js").then(t=>t.k);return{triggerFieldConfig:s}},__vite__mapDeps([0,1,2,3]));for(const s of F.value)if(s.fieldtype==="Select"||s.fieldtype==="Autocomplete"){const t=await e(v.value,s,l.value);t.options&&t.options!==s.options&&(J.value[s.fieldname]=t.options.split(`
`).filter(a=>a.trim()))}}async function P(e){const s=e?.silent??!1;window.dispatchEvent(new CustomEvent("sync-form-builder-fields")),await new Promise(t=>requestAnimationFrame(t)),w.value=!0;try{if(v.value==="Customize Form"&&l.value.pg_type){const n=(await Se.call("jingrow.handler.run_pg_method",{pgs:JSON.stringify(l.value),method:"save_customization"}))?.pgs?.[0];n&&Object.keys(n).forEach(p=>{l.value[p]=n[p]}),s||b.success(o("Saved successfully"));return}const t=await Be(v.value,l.value);t.success?(s||b.success(o("Saved successfully")),await E()):b.error(t.message||o("Save failed"))}catch(t){b.error(o("Save failed")),console.error("Save failed:",t)}finally{w.value=!1}}function re(){m.push("/")}function V(e){const s=e.detail;s&&S.value.some(t=>t.key===s)&&(D.value=s)}return me(async()=>{window.addEventListener("switch-active-tab",V),await Fe(),await E()}),ve(()=>{window.removeEventListener("switch-active-tab",V)}),pe(()=>f.params.entity,async(e,s)=>{e!==s&&await E()}),(e,s)=>(r(),u("div",Oe,[c("div",Ee,[h(i(A),{justify:"space-between",align:"center"},{default:g(()=>[c("div",null,[c("h1",Ne,C(q.value),1),c("p",$e,C(H.value),1)]),h(i(A),null,{default:g(()=>[h(i(M),{type:"default",onClick:re,disabled:w.value},{icon:g(()=>[h(i(L),null,{default:g(()=>[h(i(z),{icon:"tabler:arrow-left"})]),_:1})]),default:g(()=>[x(" "+C(i(o)("Back")),1)]),_:1},8,["disabled"]),O.value?(r(),U(i(M),{key:0,type:"primary",disabled:w.value,onClick:P,class:"save-btn-brand"},{icon:g(()=>[h(i(L),null,{default:g(()=>[h(i(z),{icon:"tabler:check"})]),_:1})]),default:g(()=>[x(" "+C(i(o)("Save")),1)]),_:1},8,["disabled"])):R("",!0)]),_:1})]),_:1})]),c("div",Je,[c("div",Pe,[Y.value?(r(),u("div",Re,[c("ul",Ie,[(r(!0),u(T,null,B(S.value,t=>(r(),u("li",{key:t.key,class:"nav-item",onClick:a=>D.value=t.key},[c("a",{class:j(["nav-link",{active:D.value===t.key}]),href:"#"},C(i(o)(t.label)),3)],8,Ve))),128))])])):R("",!0),c("div",Ae,[(r(!0),u(T,null,B(S.value,t=>(r(),u("div",{key:t.key,class:j(["tab-pane",{active:D.value===t.key}])},[c("div",Me,[(r(!0),u(T,null,B(Q(t),a=>(r(),u("div",{key:a.key,class:"form-section"},[a.label&&!I({fieldname:a.label,fieldtype:"Section Break"})?(r(),u("div",xe,[c("h4",null,C(i(o)(a.label)),1)])):R("",!0),c("div",Le,[(r(!0),u(T,null,B(a.columns,n=>(r(),u("div",{key:n.key,class:"form-column"},[(r(!0),u(T,null,B(n.fields,p=>ge((r(),U(ke,{key:p.fieldname,df:p,record:l.value,canEdit:O.value,ctx:{t:i($),getSelectOptions:X,toDateValue:Z,updateDateValue:ee,handleButtonClick:ne,getJsonDisplayValue:ae,updateJsonValue:se,formatJson:te,entity:i(v),id:i(v),reload:async()=>{await E()},save:P,saveSilent:()=>P({silent:!0}),onFieldChange:i(W)}},null,8,["df","record","canEdit","ctx"])),[[he,ie(p)]])),128))]))),128))])]))),128))])],2))),128))])])])]))}}),Ye=De(Ue,[["__scopeId","data-v-86ab2536"]]);export{Ye as default};
