Files
bruno/app/dist/spa/assets/ChildrenStep-Di1mJZJ4.js
2026-02-19 18:54:57 +01:00

2 lines
10 KiB
JavaScript

import{$ as Ve,a as H,r as y,Z as O,o as Ne,j as S,w as R,a0 as q,a3 as c,a1 as i,a4 as s,ae as I,a5 as u,a8 as m,a9 as r,a6 as h,am as z,aa as g,af as b,an as F,ab as qe,ac as ke,a7 as M,ao as k,ap as we,ah as E,aq as xe,ar as Ae}from"./index-GXFLJtQL.js";import{a as J}from"./QSelect-mYEcqVHl.js";import{Q as Fe,a as Te,b as P}from"./QList-BZpTot_c.js";import{Q as Y}from"./QChip-DE2_FO3B.js";import{Q as Z}from"./userstore-SjLknvTP.js";import{A as De}from"./AddressModal-Y6dYCZ_T.js";import{u as Qe}from"./children-CpfEvZEN.js";import{u as Se}from"./taxstore-CFm87Oqg.js";import{C as Me}from"./CommentAttachment-DGUhSBXt.js";import{u as $e}from"./vue-i18n.runtime-BXSOjn_j.js";import{_ as Ue}from"./IndexPage-C20RwqJI.js";import"./QMenu-MNqKCtrf.js";import"./LocalStorage-DjXJ9f5H.js";const Le={class:"row items-center"},je={class:"col"},Be={class:"text-h6"},He={class:"col-auto"},Oe={class:"row items-center"},Re={class:"col"},Ie={class:"col-auto"},ze={key:0,class:"q-mt-md"},Ee={class:"text-subtitle2 q-mb-sm"},Je={class:"text-weight-bold"},Pe={key:1,class:"q-mt-md"},Ye={class:"text-h6"},Ze={class:"row items-center q-gutter-sm q-mt-none"},Ge={class:"col"},Ke={key:0,class:"q-mt-none"},We={key:0,class:"q-ml-lg q-mt-none"},Xe={class:"row items-center q-gutter-sm q-mb-xs"},et={class:"col-auto"},tt={class:"col"},lt={class:"text-caption"},at={class:"q-pa-xs bg-grey-2 q-px-md"},st={key:0,class:"text-negative"},nt={key:1,class:"q-pa-xs"},ot={class:"row"},rt=Ve({__name:"ChildrenStep",props:{step:{}},emits:["next","prev"],setup(G,{expose:K,emit:W}){const $=G,U=W,{t:n}=$e(),f=Qe(),X=Se(),L=H(()=>{const t=X.getTaxpayer()?.lastName;return typeof t=="string"?t.trim():""}),T=y(null),ee=(t="Required")=>{const e=n("validation.required");return e&&e!=="validation.required"?e:t},D=t=>e=>{const l=ee();return e==null?l:typeof e=="string"?e.trim()!==""||l:Array.isArray(e)?e.length>0||l:!0},j=(t,e)=>l=>{const d=`${n("validation.minLength")||`Minimum ${t} chars`}`;return l==null?!0:typeof l=="string"?l.trim().length>=t||d:!0},te=(t,e)=>l=>{const d=n("validation.maxAgeFromJan1"),C=typeof d=="string"?d:`Age must be at most ${t} years from Jan 1 of this year`;if(!l)return!0;let A;if(l instanceof Date)A=l;else if(typeof l=="string")A=new Date(l);else return C;if(isNaN(A.getTime()))return C;const be=new Date,_e=new Date(be.getFullYear()-t,0,1);return A>=_e||C},le=t=>{if(!t)return"";const e=t.country,l=typeof e=="object"&&e!==null?e.code:e,d=typeof e=="object"&&e!==null?e.name:"";return l==="CH"?[t.street,String(t.zip||""),t.city,t.canton||""].filter(Boolean).join(", "):[t.street,String(t.zip||""),t.city,d].filter(Boolean).join(", ")};function B(t){const e=a[t]??"",l=typeof e=="string"?e.trim():String(e);if(!l){a[t]="";return}a[t]=l.charAt(0).toUpperCase()+l.slice(1)}function ae(){const t=L.value;t&&(a.lastName=t)}function se(t){if(!t)return"";const e=new Date(t);if(isNaN(e.getTime()))return"";const l=new Date;let d=l.getFullYear()-e.getFullYear();const C=l.getMonth()-e.getMonth();return(C<0||C===0&&l.getDate()<e.getDate())&&d--,d<0?"":`${d} anni`}const Q=()=>({firstName:"",lastName:"",birthDate:"",sameHousehold:!0,school:"",hasCareCost:!1,careCosts:{comments:"",attachments:[]},address:null,alimentiVersati:!1}),o=O({hasChildren:!1,children:[],moreThanFiveChildrenNote:""}),w=y(!1),p=y(!1),_=y(null),a=O({...Q()}),x=y(null),N=y(!1),V=y(null),ne=H(()=>{const t=V.value;return t?fe(t):""}),oe=[D(),j(2)],re=[D(),j(2)],ie=[D(),te(25)];async function de(){_.value=null,Object.assign(a,Q()),a.address=null,p.value=!0,await S(),x.value?.resetValidation?.()}async function ue(t){const e=o.children[t];e&&(_.value=t,Object.assign(a,{...Q(),...e}),a.address=e.address||null,V.value=a.address||null,p.value=!0,await S(),x.value?.resetValidation?.())}function ce(){p.value=!1}function me(){a.address?V.value=a.address:V.value=null,N.value=!0}function he(){N.value=!1}function fe(t){function e(d){return typeof d=="object"&&d!==null&&Object.prototype.hasOwnProperty.call(d,"name")}const l=t.country&&typeof t.country=="object"&&e(t.country)?t.country.name:t.country||"";return`${t.street||""} ${t.zip||""} ${t.city||""} ${l||""}`}function pe(t){V.value=t,a.address=t,N.value=!1}async function ve(){try{if(await(x.value?.validate?.()??!0)===!1)return}catch{return}if(_.value===null){if(o.children.length>=5){p.value=!1,w.value=!0;return}if(o.children.push({...a}),f.setChildren(v()),o.children.length===5){p.value=!1,w.value=!0;return}}else o.children[_.value]={...a},f.setChildren(v());p.value=!1}function Ce(t){o.children.splice(t,1),f.setChildren(v())}Ne(async()=>{const t=f.getChildren();if(t){if(o.hasChildren=!!t.hasChildren,Array.isArray(t.children)&&t.children.length)for(let e=0;e<5;e++)t.children[e]&&(o.children[e]={...o.children[e],...t.children[e]});o.moreThanFiveChildrenNote=t.moreThanFiveChildrenNote||"",(t.moreThanFiveChildrenNote||Array.isArray(t.children)&&t.children.length>=5)&&(w.value=!0)}await S(),T.value?.resetValidation?.()}),R(()=>o.hasChildren,()=>{f.setChildren(v())}),R(()=>o.moreThanFiveChildrenNote,()=>{f.setChildren(v())});function v(){const t={hasChildren:o.hasChildren,children:o.children.filter(e=>e.firstName||e.lastName||e.birthDate),moreThanFiveChildrenNote:o.moreThanFiveChildrenNote};return t.children=t.children.slice(0,5),t}async function ye(){try{if(await(T.value?.validate?.()??!0)===!1)return}catch{return}const t=v();f.setChildren(t),U("next",$.step?.next)}function ge(){const t=v();f.setChildren(t),U("prev",$.step?.prev)}return K({buildPayload:v}),(t,e)=>(c(),q(E,{flat:"",class:"full-width q-pa-none"},{default:i(()=>[s(I,{class:"full-width"},{default:i(()=>[u("div",Le,[u("div",je,[u("div",Be,m(r(n)("CHD")),1)]),u("div",He,[s(h,{flat:"",label:r(n)("button.prev"),onClick:ge,class:"q-mr-sm"},null,8,["label"]),s(h,{color:"primary",label:r(n)("button.next"),onClick:ye},null,8,["label"])])]),s(z,{class:"q-my-sm"}),s(Y,{ref_key:"formRef",ref:T,class:"q-gutter-md q-mt-md"},{default:i(()=>[u("div",Oe,[u("div",Re,[s(F,{modelValue:o.hasChildren,"onUpdate:modelValue":e[0]||(e[0]=l=>o.hasChildren=l),label:r(n)("children.hasChildren")},null,8,["modelValue","label"])]),u("div",Ie,[o.hasChildren?(c(),q(h,{key:0,disable:o.children.length>=5,color:"primary",label:`+ ${r(n)("children.addChild")}`,onClick:de},null,8,["disable","label"])):b("",!0)])]),o.hasChildren?(c(),g("div",ze,[u("div",Ee,m(r(n)("children.listTitle")),1),s(Fe,{bordered:""},{default:i(()=>[(c(!0),g(qe,null,ke(o.children,(l,d)=>(c(),q(Te,{key:d,clickable:""},{default:i(()=>[s(P,null,{default:i(()=>[s(J,null,{default:i(()=>[u("span",Je,m(l.firstName||"-")+" "+m(l.lastName||"")+" ("+m(se(l.birthDate))+")",1)]),_:2},1024),a.sameHousehold?b("",!0):(c(),q(J,{key:0},{default:i(()=>[M(m(le(l.address)),1)]),_:2},1024))]),_:2},1024),s(P,{side:"",class:"row items-center q-gutter-sm"},{default:i(()=>[s(h,{dense:"",flat:"",round:"",icon:"edit",onClick:C=>ue(d)},null,8,["onClick"]),s(h,{dense:"",flat:"",round:"",icon:"delete",color:"negative",onClick:C=>Ce(d)},null,8,["onClick"])]),_:2},1024)]),_:2},1024))),128))]),_:1})])):b("",!0),w.value||o.children.length>=5?(c(),g("div",Pe,[s(k,{type:"textarea",modelValue:o.moreThanFiveChildrenNote,"onUpdate:modelValue":e[1]||(e[1]=l=>o.moreThanFiveChildrenNote=l),label:r(n)("children.moreThanFiveChildrenNote"),autogrow:""},null,8,["modelValue","label"])])):b("",!0)]),_:1},512),s(we,{modelValue:p.value,"onUpdate:modelValue":e[13]||(e[13]=l=>p.value=l),persistent:""},{default:i(()=>[s(E,{class:"contained-card child-modal"},{default:i(()=>[s(I,null,{default:i(()=>[u("div",Ye,m(_.value===null?r(n)("children.addChild"):r(n)("children.editChild")),1),s(z,{class:"q-my-sm"}),s(Y,{ref_key:"modalFormRef",ref:x,class:"q-gutter-md q-mt-md"},{default:i(()=>[s(k,{class:"q-mt-none",dense:"",modelValue:a.firstName,"onUpdate:modelValue":e[2]||(e[2]=l=>a.firstName=l),label:r(n)("children.firstName"),rules:oe,onBlur:e[3]||(e[3]=l=>B("firstName"))},null,8,["modelValue","label"]),s(k,{class:"q-mt-none",dense:"",modelValue:a.lastName,"onUpdate:modelValue":e[4]||(e[4]=l=>a.lastName=l),label:r(n)("children.lastName"),rules:re,onBlur:e[5]||(e[5]=l=>B("lastName"))},{prepend:i(()=>[s(h,{dense:"",flat:"",round:"",color:"primary",icon:"family_restroom",disable:!L.value,onClick:xe(ae,["stop","prevent"])},{default:i(()=>[s(Z,{class:"bg-primary text-white"},{default:i(()=>[M(m(r(n)("children.copyLastNameFromTaxpayer")),1)]),_:1})]),_:1},8,["disable"])]),_:1},8,["modelValue","label"]),s(k,{class:"q-mt-none",dense:"",modelValue:a.birthDate,"onUpdate:modelValue":e[6]||(e[6]=l=>a.birthDate=l),type:"date",label:r(n)("children.birthDate"),rules:ie},null,8,["modelValue","label"]),u("div",Ze,[u("div",Ge,[s(F,{class:"q-mt-none",modelValue:a.sameHousehold,"onUpdate:modelValue":e[7]||(e[7]=l=>a.sameHousehold=l),label:r(n)("children.sameHousehold")},null,8,["modelValue","label"]),a.sameHousehold?b("",!0):(c(),g("div",Ke,[s(F,{class:"q-mt-none",modelValue:a.alimentiVersati,"onUpdate:modelValue":e[8]||(e[8]=l=>a.alimentiVersati=l),label:r(n)("children.alimentiVersati")},null,8,["modelValue","label"])]))])]),a.sameHousehold?b("",!0):(c(),g("div",We,[u("div",Xe,[u("div",et,[s(h,{dense:"",flat:"",round:"",icon:"edit",onClick:me},{default:i(()=>[s(Z,{class:"bg-primary text-white"},{default:i(()=>[M(m(r(n)("children.editAddress")),1)]),_:1})]),_:1})]),u("div",tt,[u("div",lt,m(r(n)("children.addressLabel")),1)])]),u("div",at,[a.address?(c(),g("div",nt,m(ne.value),1)):(c(),g("div",st,m(r(n)("validation.insertAddress")),1))])])),s(k,{class:"q-mt-none",dense:"",modelValue:a.school,"onUpdate:modelValue":e[9]||(e[9]=l=>a.school=l),label:r(n)("children.school")},null,8,["modelValue","label"]),u("div",ot,[s(F,{class:"q-mt-none",modelValue:a.hasCareCost,"onUpdate:modelValue":e[10]||(e[10]=l=>a.hasCareCost=l),label:r(n)("children.hasCareCost")},null,8,["modelValue","label"]),a.hasCareCost?(c(),q(Me,{key:0,class:"q-mt-none",modelValue:a.careCosts,"onUpdate:modelValue":e[11]||(e[11]=l=>a.careCosts=l),label:r(n)("children.careCosts"),id:"children"},null,8,["modelValue","label"])):b("",!0)])]),_:1},512)]),_:1}),s(De,{modelValue:N.value,"onUpdate:modelValue":e[12]||(e[12]=l=>N.value=l),modelAddress:V.value,allowForeign:!1,onSave:pe,onCancel:he},null,8,["modelValue","modelAddress"]),s(Ae,{align:"right"},{default:i(()=>[s(h,{flat:"",label:r(n)("button.cancel"),onClick:ce},null,8,["label"]),s(h,{color:"primary",label:_.value===null?r(n)("button.add"):r(n)("button.save"),onClick:ve},null,8,["label"])]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}))}}),_t=Ue(rt,[["__scopeId","data-v-aa36bd22"]]);export{_t as default};