import { modalController } from "@ionic/core";
export class FormController {
  /**
   * Display a form in a modal. If the form is canceled, it resolves to
   * `undefined`. If the form is submitted, it resolves to the GeoJSON
   * feature updated by the form.
   * @param feature The GeoJSON feature that the form will edit.
   * @param options Option object used to set the properties of the `gl-form`.
   */
  async create(feature, options) {
    let form = document.createElement("gl-form");
    form.feature = feature;
    for (let optionName in options)
      form[optionName] = options[optionName];
    const modal = await modalController.create({
      component: form,
    });
    await modal.present();
    return await new Promise((resolve) => {
      form.addEventListener("glFormCancel", () => {
        modal.dismiss();
        resolve(undefined);
      });
      form.addEventListener("glFormSubmit", () => {
        modal.dismiss();
        resolve(feature);
      });
    });
  }
  static get is() { return "gl-form-controller"; }
  static get methods() {
    return {
      "create": {
        "complexType": {
          "signature": "(feature: { properties: { [key: string]: any; }; }, options: FormOptions) => Promise<any>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "feature The GeoJSON feature that the form will edit."
                }],
              "text": "The GeoJSON feature that the form will edit."
            }, {
              "tags": [{
                  "name": "param",
                  "text": "options Option object used to set the properties of the `gl-form`."
                }],
              "text": "Option object used to set the properties of the `gl-form`."
            }],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            },
            "FormOptions": {
              "location": "import",
              "path": "./interface",
              "id": "src/components/form-controller/interface.ts::FormOptions"
            }
          },
          "return": "Promise<any>"
        },
        "docs": {
          "text": "Display a form in a modal. If the form is canceled, it resolves to\n`undefined`. If the form is submitted, it resolves to the GeoJSON\nfeature updated by the form.",
          "tags": [{
              "name": "param",
              "text": "feature The GeoJSON feature that the form will edit."
            }, {
              "name": "param",
              "text": "options Option object used to set the properties of the `gl-form`."
            }]
        }
      }
    };
  }
}
//# sourceMappingURL=form-controller.js.map
