import{t as e}from"./axios-DHQprbt3.js";import{E as t,M as n,O as r,c as i,ct as a,d as o,h as s,i as c,t as l,w as u}from"./_plugin-vue_export-helper-Conii5fq.js";import{a as d,c as f}from"./runtime-dom.esm-bundler-CI28bPhn.js";import{t as p}from"./vue-multiselect.esm-ClUY7h_I.js";var m={name:`ContactPersonForm`,components:{Multiselect:p},props:{contactPerson:{type:Object,default:()=>({name:``,phone:``,street:``,zipcode:``,city:``,email:``,expiryDate:null,positions:[]})},positions:{type:Array,required:!0}},data(){return{localContactPerson:{...this.contactPerson},selectedPositions:this.contactPerson.positions||[]}},watch:{contactPerson:{handler(e){this.localContactPerson={...e},this.selectedPositions=e.positions||[]},deep:!0,immediate:!0},selectedPositions(e){this.localContactPerson.positions=e}},methods:{async saveContactPerson(){try{let t=this.selectedPositions.map(e=>e.id),n={...this.localContactPerson,positionIds:t};this.localContactPerson.id?await e.put(`/contact-persons/${this.localContactPerson.id}`,n):await e.post(`/contact-persons`,n),this.$emit(`contactPersonSaved`)}catch(e){console.error(`Fehler beim Speichern der Kontaktperson:`,e)}},resetForm(){this.localContactPerson={name:``,phone:``,street:``,zipcode:``,city:``,email:``,expiryDate:null,positions:[]},this.selectedPositions=[]}}},h={class:`contact-person-form`};function g(e,t,a,c,l,p){let m=r(`multiselect`);return u(),o(`div`,h,[t[19]||=i(`h2`,null,`Kontaktperson Formular`,-1),i(`form`,{onSubmit:t[9]||=f((...e)=>p.saveContactPerson&&p.saveContactPerson(...e),[`prevent`])},[t[10]||=i(`label`,{for:`name`},`Name:`,-1),n(i(`input`,{type:`text`,id:`name`,"onUpdate:modelValue":t[0]||=e=>l.localContactPerson.name=e,required:``},null,512),[[d,l.localContactPerson.name]]),t[11]||=i(`label`,{for:`phone`},`Telefon:`,-1),n(i(`input`,{type:`text`,id:`phone`,"onUpdate:modelValue":t[1]||=e=>l.localContactPerson.phone=e},null,512),[[d,l.localContactPerson.phone]]),t[12]||=i(`label`,{for:`street`},`Straße:`,-1),n(i(`input`,{type:`text`,id:`street`,"onUpdate:modelValue":t[2]||=e=>l.localContactPerson.street=e},null,512),[[d,l.localContactPerson.street]]),t[13]||=i(`label`,{for:`zipcode`},`PLZ:`,-1),n(i(`input`,{type:`text`,id:`zipcode`,"onUpdate:modelValue":t[3]||=e=>l.localContactPerson.zipcode=e},null,512),[[d,l.localContactPerson.zipcode]]),t[14]||=i(`label`,{for:`city`},`Ort:`,-1),n(i(`input`,{type:`text`,id:`city`,"onUpdate:modelValue":t[4]||=e=>l.localContactPerson.city=e},null,512),[[d,l.localContactPerson.city]]),t[15]||=i(`label`,{for:`email`},`Email:`,-1),n(i(`input`,{type:`email`,id:`email`,"onUpdate:modelValue":t[5]||=e=>l.localContactPerson.email=e},null,512),[[d,l.localContactPerson.email]]),t[16]||=i(`label`,{for:`expiryDate`},`Ablaufdatum (optional):`,-1),n(i(`input`,{type:`date`,id:`expiryDate`,"onUpdate:modelValue":t[6]||=e=>l.localContactPerson.expiryDate=e},null,512),[[d,l.localContactPerson.expiryDate]]),t[17]||=i(`label`,{for:`positions`},`Positionen:`,-1),s(m,{modelValue:l.selectedPositions,"onUpdate:modelValue":t[7]||=e=>l.selectedPositions=e,options:a.positions,multiple:!0,"close-on-select":!1,"clear-on-select":!1,"preserve-search":!0,placeholder:`Wähle einige`,label:`caption`,"track-by":`id`,"preselect-first":!1},null,8,[`modelValue`,`options`]),t[18]||=i(`button`,{type:`submit`},`Speichern`,-1),i(`button`,{type:`button`,onClick:t[8]||=(...e)=>p.resetForm&&p.resetForm(...e)},`Neue Kontaktperson`)],32)])}var _={name:`ContactPersonManagement`,components:{ContactPersonForm:l(m,[[`render`,g],[`__scopeId`,`data-v-11c9f1c3`]])},data(){return{contactPersons:[],selectedContactPerson:{name:``,phone:``,street:``,zipcode:``,city:``,email:``,expiryDate:null,positions:[]},positions:[]}},created(){this.fetchContactPersons(),this.fetchPositions()},methods:{async fetchContactPersons(){try{this.contactPersons=(await e.get(`/contact-persons`)).data}catch(e){console.error(`Fehler beim Abrufen der Kontaktpersonen:`,e)}},async fetchPositions(){try{this.positions=(await e.get(`/positions`)).data}catch(e){console.error(`Fehler beim Abrufen der Positionen:`,e)}},selectContactPerson(e){this.selectedContactPerson=e}}},v=[`onClick`];function y(e,n,l,d,f,p){let m=r(`ContactPersonForm`);return u(),o(`div`,null,[n[0]||=i(`h1`,null,`Kontaktpersonen Verwaltung`,-1),s(m,{contactPerson:f.selectedContactPerson,positions:f.positions,onContactPersonSaved:p.fetchContactPersons},null,8,[`contactPerson`,`positions`,`onContactPersonSaved`]),i(`ul`,null,[(u(!0),o(c,null,t(f.contactPersons,e=>(u(),o(`li`,{key:e.id,onClick:t=>p.selectContactPerson(e)},a(e.name),9,v))),128))])])}var b=l(_,[[`render`,y],[`__scopeId`,`data-v-5365b0dc`]]);export{b as default};
//# sourceMappingURL=ContactPersonManagement-DtzQTtlj.js.map