import { BaseField } from '@dvn/core/doldurma/src/BaseField';
import '@dvn/core/doldurma/src/fields/text';
import { injectContext } from '@dvn/core/global/context';
import { Component, h, Host, Prop, State } from '@stencil/core';
export class DvnMemberInfoForm {
  constructor() {
    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 (h(Host, { class: "d-block" },
      h("doldurma-form", { fields: membership.config.fields
          .filter(field => field.id !== 'user') // remove the user from the form
          .map(field => (BaseField.decode(Object.assign(Object.assign({}, field), { value: membership[field.id] })))), onSubmit: this.onSubmit, submitButtonLabel: "Save", progressing: progressing })));
  }
  static get is() { return "dvn-member-info-form"; }
  static get properties() { return {
    "apiUye": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "UyeApi",
        "resolved": "UyeApi",
        "references": {
          "UyeApi": {
            "location": "import",
            "path": "@dvn/uye/api"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "membership": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Membership",
        "resolved": "Membership",
        "references": {
          "Membership": {
            "location": "import",
            "path": "@dvn/core/models/membership"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "appContextInvalidator": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AppContextInvalidator",
        "resolved": "() => void",
        "references": {
          "AppContextInvalidator": {
            "location": "import",
            "path": "@dvn/core/global/context/context"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "error": {},
    "progressing": {}
  }; }
}
injectContext(DvnMemberInfoForm);
