import{t as e}from"./axios-DHQprbt3.js";import{E as t,M as n,c as r,ct as i,d as a,i as o,t as s,u as c,w as l}from"./_plugin-vue_export-helper-Conii5fq.js";import{a as u,c as d}from"./runtime-dom.esm-bundler-CI28bPhn.js";var f={name:`InstitutionManagement`,data(){return{institutions:[],contactPersons:[],institutionData:{name:``,street:``,zipcode:``,city:``,phone:``,fax:``,email:``},selectedInstitution:null,showForm:!1,editMode:!1,editId:null}},created(){this.fetchInstitutions(),this.fetchContactPersons()},methods:{async fetchInstitutions(){try{this.institutions=(await e.get(`/institutions`)).data}catch(e){console.error(`Fehler beim Abrufen der Institutionen:`,e)}},async fetchContactPersons(){try{this.contactPersons=(await e.get(`/contact-persons`)).data}catch(e){console.error(`Fehler beim Abrufen der Kontaktpersonen:`,e)}},async saveInstitution(){try{if(this.editMode)await e.put(`/institutions/${this.editId}`,this.institutionData);else{let t=await e.post(`/institutions`,this.institutionData);this.institutions.push(t.data)}this.resetForm(),await this.fetchInstitutions()}catch(e){console.error(`Fehler beim Speichern der Institution:`,e)}},editInstitution(e){this.institutionData={...e},this.editMode=!0,this.editId=e.id,this.showForm=!0},async deleteInstitution(t){try{await e.delete(`/institutions/${t}`),this.fetchInstitutions()}catch(e){console.error(`Fehler beim Löschen der Institution:`,e)}},resetForm(){this.institutionData={name:``,street:``,zipcode:``,city:``,phone:``,fax:``,email:``},this.editMode=!1,this.editId=null,this.showForm=!1},showCreateForm(){this.resetForm(),this.showForm=!0}}},p={class:`institution-management`},m=[`onClick`],h=[`onClick`];function g(e,s,f,g,_,v){return l(),a(`div`,p,[s[18]||=r(`h2`,null,`Institutionenverwaltung`,-1),r(`form`,{onSubmit:s[8]||=d((...e)=>v.saveInstitution&&v.saveInstitution(...e),[`prevent`])},[s[9]||=r(`label`,{for:`name`},`Name:`,-1),n(r(`input`,{type:`text`,id:`name`,"onUpdate:modelValue":s[0]||=e=>_.institutionData.name=e,required:``},null,512),[[u,_.institutionData.name]]),s[10]||=r(`label`,{for:`street`},`Straße:`,-1),n(r(`input`,{type:`text`,id:`street`,"onUpdate:modelValue":s[1]||=e=>_.institutionData.street=e},null,512),[[u,_.institutionData.street]]),s[11]||=r(`label`,{for:`zipcode`},`PLZ:`,-1),n(r(`input`,{type:`text`,id:`zipcode`,"onUpdate:modelValue":s[2]||=e=>_.institutionData.zipcode=e},null,512),[[u,_.institutionData.zipcode]]),s[12]||=r(`label`,{for:`city`},`Stadt:`,-1),n(r(`input`,{type:`text`,id:`city`,"onUpdate:modelValue":s[3]||=e=>_.institutionData.city=e},null,512),[[u,_.institutionData.city]]),s[13]||=r(`label`,{for:`phone`},`Telefon:`,-1),n(r(`input`,{type:`text`,id:`phone`,"onUpdate:modelValue":s[4]||=e=>_.institutionData.phone=e},null,512),[[u,_.institutionData.phone]]),s[14]||=r(`label`,{for:`fax`},`Fax:`,-1),n(r(`input`,{type:`text`,id:`fax`,"onUpdate:modelValue":s[5]||=e=>_.institutionData.fax=e},null,512),[[u,_.institutionData.fax]]),s[15]||=r(`label`,{for:`email`},`Email:`,-1),n(r(`input`,{type:`email`,id:`email`,"onUpdate:modelValue":s[6]||=e=>_.institutionData.email=e},null,512),[[u,_.institutionData.email]]),s[16]||=r(`button`,{type:`submit`},`Speichern`,-1),_.editMode?(l(),a(`button`,{key:0,type:`button`,onClick:s[7]||=(...e)=>v.resetForm&&v.resetForm(...e)},`Neue Institution erstellen`)):c(``,!0)],32),r(`table`,null,[s[17]||=r(`thead`,null,[r(`tr`,null,[r(`th`,null,`Name`),r(`th`,null,`Bearbeiten`),r(`th`,null,`Löschen`)])],-1),r(`tbody`,null,[(l(!0),a(o,null,t(_.institutions,e=>(l(),a(`tr`,{key:e.id},[r(`td`,null,i(e.name),1),r(`td`,null,[r(`button`,{onClick:t=>v.editInstitution(e)},`Bearbeiten`,8,m)]),r(`td`,null,[r(`button`,{onClick:t=>v.deleteInstitution(e.id)},`Löschen`,8,h)])]))),128))])])])}var _=s(f,[[`render`,g],[`__scopeId`,`data-v-ca4b9ed0`]]);export{_ as default};
//# sourceMappingURL=InstitutionManagement-EjPRSjMJ.js.map