import{r as t,h as s}from"./p-9f21f85f.js";import{c as r}from"./p-04f5d146.js";import{g as o}from"./p-f2965a61.js";import{S as i}from"./p-1187cc7c.js";import{f as e}from"./p-35eb47f9.js";import{S as p}from"./p-c2c9e896.js";import"./p-25d382ec.js";import"./p-3968aca6.js";import"./p-d343a062.js";import{g as m,c as n,m as a}from"./p-c44f96b9.js";import{s as c,d as f,e as d}from"./p-cb585cde.js";import{F as j}from"./p-8e52c7df.js";import{T as h}from"./p-293acc32.js";import{A as u}from"./p-5d192a8d.js";import{b as l}from"./p-905285ef.js";import{c as b}from"./p-33c4053b.js";import"./p-0563ceba.js";import"./p-105f7627.js";import"./p-1e47e7bd.js";import"./p-31e77e7b.js";import"./p-825ab276.js";import"./p-6c8be41c.js";import"./p-881a2bb8.js";import"./p-968ee2ec.js";import"./p-6a6f355f.js";import"./p-aa5ffe14.js";import"./p-d27cb594.js";import"./p-9c82afa0.js";import"./p-d6c479ab.js";import"./p-10cfccbb.js";import"./p-8d2ddf16.js";import"./p-814af281.js";import"./p-e929429b.js";import"./p-0988b316.js";import"./p-65eb3f89.js";import"./p-42939000.js";import"./p-3d141e05.js";import"./p-d59ffc5b.js";import"./p-a86d8cf2.js";import"./p-3ccedaa0.js";import"./p-9aa2fafd.js";class v{constructor(t){this.userMetadata=t;const{headers:s}=m();this.api=n(a,s)}onSubmit(t){const{values:s}=t.detail,r=s;return new Promise(((t,s)=>{let o=[];this.userMetadata&&o.push(this.api.update("metadatas",this.userMetadata._id,{data:Object.assign(Object.assign({},this.userMetadata.data),r)})),Promise.all(o).then((()=>t({}))).catch((()=>{s(["Unexpected error"])}))}))}}const w=(t,s={})=>{const p=r(t.conversionConfig,s);return t.ui.fields.map((s=>{var r;const m=o((n=s).field||e(t.table.fields,n.fieldId));var n;const a=p[m.id];if(a&&m.type===i.type){const t=m;t.dataProvider&&t.dataProvider.setInitialData([a]),m.setValue((null===(r=t.dataAdapter)||void 0===r?void 0:r.value(a))||a)}else a&&m.setValue(a);return m}))},y=class{constructor(s){t(this,s),this.isFetching=!1,this.isProgressing=!1,this.setDictionary=async()=>{const t=(new p).setLanguage(this.language).setContents(c);this.strings=await t.getContent(f,d)},this.onSubmit=(t,s)=>{s.handler.onSubmit&&(this.isProgressing=!0,this.formErrors=void 0,s.handler.onSubmit(t).then((()=>{this.isProgressing=!1,window.dispatchEvent(new CustomEvent("dvn.mentornity-user-metadata-form.go-next-step"))})).catch((t=>{this.isProgressing=!1,this.formErrors=t})))}}componentWillLoad(){const{context:{organisationId:t,role:s,userId:r},headers:o}=m(),i=n(a,o);i.getOrganisationConfig(t).then((t=>{this.organisationConfig=t})),this.setDictionary(),this.isFetching=!0,i.getMetadataOfUser(t,"mentor"===s?"mentors":"mentees",r).then((t=>{this.userMetadata=t})),this.isFetching=!1}render(){var t,r;if(this.isFetching||!this.userMetadata||!this.organisationConfig||!this.strings)return s("mentornity-root-wrapper",null,s("div",{class:"d-flex justify-content-center pt-3"},s("dvn-progress",{indefinite:!0})));const{context:o}=m(),i=function(t,s,r){const o={},{role:i}=t;return(("mentor"===i?s.metadatas.mentor:s.metadatas.mentee)||[]).map(l).forEach((t=>{o[t.id]=r.data[t.id]})),o}(o,this.organisationConfig,this.userMetadata),e=function(t,s,r){if(!s)return null;const{role:o}=t,i=function(t,s){let r=[];return r=(("mentor"===t?s.metadatas.mentor:s.metadatas.mentee)||[]).map(l),[...r]}(o,s),e=b(i);return j.decode({_id:"update-user-metadata-form",base:"mentornity",table:h.decode({name:"mentees",fields:i}),type:u.FormView,handler:new v(r),ui:{fields:e}})}(o,this.organisationConfig,this.userMetadata),p=(null===(r=null===(t=e.table)||void 0===t?void 0:t.fields)||void 0===r?void 0:r.length)>0;return s("mentornity-root-wrapper",null,!p&&s("p",null,this.strings.noMetadataFound),s("doldurma-form",{fields:w(e,i),onSubmit:t=>this.onSubmit(t,e),submitButtonLabel:p?`${this.strings.save} & ${this.strings.next}`:this.strings.next,progressing:this.isProgressing,formErrors:this.formErrors}))}};export{y as mentornity_user_metadata_form}