import{_ as q,o as i,f as d,F as g,p as y,n as v,g as V,e as _,aT as x,aZ as P,m as l,T as m,u as c,U as S,d as p,w as F,h as $}from"./index.cf09daef.js";import{F as w,a as B}from"./mixins.6734cf6a.js";const k={mixins:[w],props:{modelValue:{type:Array,default:()=>[]},readonly:Boolean},emits:["update:model-value"]},D={class:"input-from-fields row q-col-gutter-md"},C={class:"field"};function N(e,t,s,n,a,o){return i(),d("div",D,[(i(!0),d(g,null,y(s.modelValue,r=>(i(),d("div",{class:v([`col-sm-${r.config.width||6} col-xs-12`,r.config.classes]),key:r.id},[V("div",C,[(i(),_(P(`form-${r.type}`),x({modelValue:r.config.value,"onUpdate:modelValue":u=>r.config.value=u},r,{readonly:s.readonly}),null,16,["modelValue","onUpdate:modelValue","readonly"]))])],2))),128))])}var O=q(k,[["render",N]]);const f={questionnaire:{fields:[]},answers:{}},h=e=>{const{answers:t,questionnaire:s}=e,n=a=>t[a]||void 0;return e.questionnaire.fields=s.fields.map(a=>{var o;return{...a,config:{...a.config,value:n(a.key)||((o=a.config)==null?void 0:o.value)}}}),console.log(e),e},U={components:{InputFromFields:O},props:{member:Object,requestParq:Boolean,readonly:Boolean},data(){return{parq:l.exports.cloneDeep(f),defaultParq:l.exports.cloneDeep(f)}},emits:["done"],methods:{...m(B,["default"]),...m(c,["updateParq"]),async onSubmit(e){var t;console.func("components/ParqForm:methods.onSubmit()",arguments),this.updateParq({fields:this.fields,user_id:this.member.id,questionnaire_id:(t=this.parq.questionnaire)==null?void 0:t.id}).then(({message:s,data:n})=>{const a=h(n);this.$emit("done",a),this.$core.success(s),this.parq=a}).catch(s=>{this.$core.error(s,{title:this.$t("dialog.title.error")})})}},computed:{...S(c,["user"]),fields(){var e;return((e=this.parq.questionnaire)==null?void 0:e.fields)||[]},disable(){return this.requires.length>0||JSON.stringify(this.parq)===JSON.stringify(this.defaultParq)},requires(){return this.fields.filter(({config:e})=>e.required&&!e.value)},noRequires(){return this.fields.filter(({config:e})=>e.skip&&e.value).length>0}},watch:{member:{deep:!0,handler(e){this.parq={...this.parq,...e}}}},async mounted(){this.member.parq?this.parq=h(l.exports.cloneDeep(this.member.parq)):await this.default().then(e=>{Object.assign(this.parq,{user:this.member,questionnaire:e})}),this.defaultParq=l.exports.cloneDeep(this.parq)}};function A(e,t,s,n,a,o){const r=p("input-from-fields"),u=p("base-form");return i(),_(u,{disable:o.disable,"no-action":s.readonly,"save-label":e.$t("submit"),cancelable:!1,class:"parq-form",onSubmit:o.onSubmit,"no-events":""},{default:F(()=>[$(r,{readonly:s.readonly,modelValue:o.fields,"onUpdate:modelValue":t[0]||(t[0]=b=>o.fields=b)},null,8,["readonly","modelValue"])]),_:1},8,["disable","no-action","save-label","onSubmit"])}var Q=q(U,[["render",A]]);export{Q as P};
