import{b as q,A as F}from"./CommentAttachment-Cd2tEdil.js";import{$ as S,r as v,a as i,a9 as d,a3 as u,a5 as s,a4 as m,a1 as _,a7 as j,a8 as c,ac as p,a6 as I}from"./index-BmjEiQ1N.js";import{u as N}from"./vue-i18n.runtime-BJiJhJjW.js";import{_ as z}from"./IndexPage-B-pkHUHg.js";const T={class:"row items-center q-gutter-sm q-mb-sm q-mt-md"},E={class:"col-auto"},H={class:"col"},M={class:"text-caption"},O={class:"q-pa-sm bg-grey-2 q-mb-sm"},Q={key:0,class:"text-negative"},D={key:1},U=S({__name:"AddressInput",props:{modelValue:{},label:{},allowForeign:{type:Boolean},hint:{}},emits:["update:modelValue","save","cancel"],setup(g,{emit:h}){const o=g,r=h,{t:l}=N(),n=v(!1),y=v(null),V=o.label||l("address"),b=o.allowForeign??!0,x=i(()=>{const e=o.modelValue;if(console.log("address input formatted",e),!e)return"";const t=e.country?.name||"";return e.country.code==="CH"?[e.street,String(e.cap||""),e.city,e.canton].filter(Boolean).join(", "):[e.street,String(e.cap||""),e.city,t].filter(Boolean).join(", ")}),A=i(()=>{const e=o.modelValue;return e?!(e.street||e.city||e.cap||e.country&&e.country.code):!0}),w=i(()=>o.hint||l("validation.insertAddress"));function B(){const e=o.modelValue;y.value=e?{street:e.street||"",zip:String(e.cap||""),city:e.city||"",country:e.country&&e.country.code||"",canton:e.canton||"",foreign:!!(e.country&&e.country.code&&e.country.code!=="CH")}:{street:"",zip:"",city:"",country:"",canton:"",foreign:!0},n.value=!0}function C(e){let t={code:"",name:""};if(!e.country)t={code:"",name:""};else if(typeof e.country=="string")t={code:e.country,name:e.country};else if(typeof e.country=="object"&&e.country!==null){const f=e.country;t={code:f.code||"",name:f.name||""}}const a={street:e.street||"",cap:e.zip||"",city:e.city||"",country:t,canton:e.canton||""};r("update:modelValue",a),r("save",a),n.value=!1}function k(){r("cancel"),n.value=!1}return(e,t)=>(u(),d("div",null,[s("div",T,[s("div",E,[m(I,{dense:"",flat:"",round:"",icon:"edit",onClick:B},{default:_(()=>[m(q,{class:"bg-primary text-white"},{default:_(()=>[j(c(p(l)("children.editAddress")),1)]),_:1})]),_:1})]),s("div",H,[s("div",M,c(p(V)),1)])]),s("div",O,[A.value?(u(),d("div",Q,c(w.value),1)):(u(),d("div",D,c(x.value),1))]),m(F,{modelValue:n.value,"onUpdate:modelValue":t[0]||(t[0]=a=>n.value=a),modelAddress:y.value,allowForeign:p(b),onSave:C,onCancel:k},null,8,["modelValue","modelAddress","allowForeign"])]))}}),L=z(U,[["__scopeId","data-v-b68f19ad"]]);export{L as A};
