'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1141a245.js');
const BaseField = require('./BaseField-381327a9.js');
require('./index-61f9621a.js');
const index$1 = require('./index-f0a95cb1.js');
require('./FieldGenerator-279a646b.js');
require('./context-d32abf1f.js');
require('./state-tunnel-786a62ce.js');

const DvnMemberInfoForm = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.onSubmit = (event) => {
      const data = event.detail.values;
      this.progressing = true;
      this.apiUye.updateMembership(this.membership.config._id, this.membership._id, data)
        .then(this.onUpdateSucceed, this.onUpdateFail)
        .finally(() => this.progressing = false);
    };
    this.onUpdateSucceed = () => {
      this.appContextInvalidator();
    };
    this.onUpdateFail = (error) => {
      this.error = error;
    };
  }
  render() {
    const { membership, progressing } = this;
    if (!membership) {
      return null;
    }
    return (index.h(index.Host, { class: "d-block" }, index.h("doldurma-form", { fields: membership.config.fields
        .filter(field => field.id !== 'user') // remove the user from the form
        .map(field => (BaseField.BaseField.decode(Object.assign(Object.assign({}, field), { value: membership[field.id] })))), onSubmit: this.onSubmit, submitButtonLabel: "Save", progressing: progressing })));
  }
};
index$1.injectContext(DvnMemberInfoForm);

exports.dvn_member_info_form = DvnMemberInfoForm;
