import { Component, Event, h, Host, Listen, Prop, State } from "@stencil/core";
export class CorejamFormContainer {
  constructor() {
    this.formData = {};
  }
  handleSubmit(e) {
    if (e.detail.name == this.name) {
      console.info("form submit");
      const data = Object.assign({}, this.formData);
      if (this.submitHandler)
        this.submitHandler(data);
      this.sendForm.emit(data);
    }
  }
  receivedFormEvent(event) {
    if (event.detail.name == this.name) {
      const formData = Object.assign(Object.assign({}, this.formData), { formId: this.name });
      console.log(formData);
      formData[event.detail.key] = event.detail;
      this.formData = formData;
    }
  }
  render() {
    return (h(Host, { as: "form" },
      h("form", { name: this.name },
        h("slot", null))));
  }
  static get is() { return "corejam-form-container"; }
  static get properties() { return {
    "name": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "name",
      "reflect": true
    },
    "submitHandler": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Function",
        "resolved": "Function",
        "references": {
          "Function": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "formData": {}
  }; }
  static get events() { return [{
      "method": "formEvent",
      "name": "formEvent",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "formSubmit",
      "name": "formSubmit",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "sendForm",
      "name": "sendForm",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get listeners() { return [{
      "name": "formSubmit",
      "method": "handleSubmit",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "formEvent",
      "method": "receivedFormEvent",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
