import{j as B,b as P,n as S,h as E,g as p,L as k,m as u,a as c,w as d,F as V,G as y,o as a,c as i,J as N,l as I,t as h,q as j,e as L,f as z}from"./index-CTxlYqj4.js";import{_ as G}from"./HtmlEditor-DfoGrUHw.js";import{V as O,a as W,b as $,c as q}from"./VTabs-DCb8kj6G.js";import{V as A}from"./VAvatar-x_79C0tA.js";import{V as D}from"./VContainer-CC8lqRXa.js";import{b as H,V as J}from"./VCard-DRptUN8Y.js";import{V as M}from"./VSwitch-HiyBjUWI.js";import{V as K}from"./VSelect-tV4GZAtn.js";import{V as Q}from"./VTextarea-Bry3a299.js";import{V as R}from"./VColorPicker-D7UlInpB.js";import{V as X}from"./VTextField-CWm47OUI.js";const Y={key:0},Z={class:"m-label"},ee={__name:"ParametersForm",props:{app:{type:String,default:""},structure:{type:Array,default:null},values:{type:Object,default:null},saveFunction:{type:Function,default:null}},emits:["success"],setup(x,{emit:F}){const m=x,U=F,{$gettext:g}=P(),{displayNotification:_}=S(),b=E(()=>m.structure.filter(s=>w(s))),v=p(0),r=p({}),l=p({}),f=p([]);k(()=>m.values,s=>{s&&(l.value={...s})}),k(l,()=>{f.value=[]});function w(s){if(s.display==="")return!0;let n=!0;return s.display.split("&").forEach(o=>{let[e,t]=o.split("=");(t==="true"||t==="false")&&(t=!!t),n&=l.value[e]===t}),n}function C(s){return s.filter(n=>w(n))}async function T(){r.value={},f.value=[];try{await m.saveFunction(m.app,l.value),_({msg:g("Parameters updated")}),U("success",l.value)}catch(s){_({msg:g("Could not save parameters"),type:"error"}),r.value=s.response.data,Object.keys(r.value).forEach(n=>{for(let o=0;o<m.structure.length;o++)m.structure[o].parameters.filter(t=>t.name===n).length>0&&f.value.push(o)})}}return(s,n)=>(a(),u(V,null,[c(O,{modelValue:v.value,"onUpdate:modelValue":n[0]||(n[0]=o=>v.value=o),"bg-color":"white"},{default:d(()=>[(a(!0),u(V,null,y(b.value,(o,e)=>(a(),i($,{key:e,color:"primary",class:N(f.value.includes(e)?"error_tab":"")},{default:d(()=>[I(h(o.label),1)]),_:2},1032,["class"]))),128))]),_:1},8,["modelValue"]),c(W,{modelValue:v.value,"onUpdate:modelValue":n[1]||(n[1]=o=>v.value=o)},{default:d(()=>[(a(!0),u(V,null,y(b.value,o=>(a(),i(q,{key:o.label},{default:d(()=>[c(D,{fluid:"",class:"pa-0"},{default:d(()=>[c(H,null,{default:d(()=>[c(J,null,{default:d(()=>[(a(!0),u(V,null,y(C(o.parameters),e=>(a(),u("div",{key:e.name,class:"my-4"},[e.widget==="SeparatorField"?(a(),u("h2",Y,h(e.label),1)):e.widget==="BooleanField"?(a(),u(V,{key:1},[e.widget==="BooleanField"?(a(),i(M,{key:0,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t,label:e.label,hint:e.help_text,error:r.value[e.name]!==void 0,color:"primary",density:"compact","error-messages":r.value[e.name],"persistent-hint":""},null,8,["modelValue","onUpdate:modelValue","label","hint","error","error-messages"])):j("",!0)],64)):(a(),u(V,{key:2},[L("label",Z,h(e.label),1),e.widget==="ChoiceField"?(a(),i(K,{key:0,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t,items:e.choices,"item-title":"text",hint:e.help_text,"persistent-hint":"",density:"compact",variant:"outlined"},null,8,["modelValue","onUpdate:modelValue","items","hint"])):e.widget==="TextareaField"?(a(),i(Q,{key:1,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t,hint:e.help_text,"persistent-hint":"",error:r.value[e.name]!==void 0,"error-messages":r.value[e.name],type:e.widget==="PasswordField"?"password":"text",density:"compact",variant:"outlined"},null,8,["modelValue","onUpdate:modelValue","hint","error","error-messages","type"])):e.widget==="HTMLField"?(a(),i(z(G),{key:2,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t},null,8,["modelValue","onUpdate:modelValue"])):e.widget==="ColorPicker"?(a(),i(R,{key:3,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t,hint:e.help_text,"persistent-hint":"",error:r.value[e.name]!==void 0,"error-messages":r.value[e.name],density:"compact",variant:"outlined"},null,8,["modelValue","onUpdate:modelValue","hint","error","error-messages"])):(a(),i(X,{key:4,modelValue:l.value[e.name],"onUpdate:modelValue":t=>l.value[e.name]=t,hint:e.help_text,"persistent-hint":"",error:r.value[e.name]!==void 0,"error-messages":r.value[e.name],type:e.widget==="PasswordField"?"password":"text",density:"compact",variant:"outlined"},null,8,["modelValue","onUpdate:modelValue","hint","error","error-messages","type"]))],64))]))),128))]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:2},1024))),128))]),_:1},8,["modelValue"]),c(A,{icon:"mdi-content-save",class:"ma-5",position:"fixed",location:"bottom right",color:"green",size:"large",onClick:T})],64))}},ce=B(ee,[["__scopeId","data-v-3d3c2602"]]);export{ce as P};
