'use strict';

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

const index = require('./index-ee190ee0.js');

const inputSearchUserCss = "";

const InputSearchUser = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ionInput = index.createEvent(this, "ionInput", 7);
    this.fireenjinSelectUser = index.createEvent(this, "fireenjinSelectUser", 7);
    this.name = undefined;
    this.label = undefined;
    this.placeholder = "Search Users";
    this.value = undefined;
    this.required = false;
    this.autofocus = undefined;
    this.disableSearch = false;
    this.disabled = undefined;
    this.endpoint = undefined;
    this.dataPropsMap = undefined;
    this.mode = "inline";
    this.iconEnd = undefined;
    this.iconStart = undefined;
    this.limit = 5;
    this.template = undefined;
    this.results = [];
    this.lines = undefined;
    this.labelPosition = undefined;
    this.selectKey = "id";
    this.pattern = undefined;
  }
  async selectUser(event, user) {
    this.value = user[this.selectKey];
    this.fireenjinSelectUser.emit({
      event,
      user,
    });
    setTimeout(async () => {
      await this.inputSearchEl.checkValidity({
        setValidationClass: true,
      });
    }, 200);
    if (this.mode === "popover") {
      await this.inputSearchEl.closePopover();
    }
    else if (this.mode === "inline") {
      await this.inputSearchEl.clearResults();
    }
  }
  render() {
    return (index.h("fireenjin-input-search", { labelPosition: this.labelPosition, lines: this.lines, iconEnd: this.iconEnd, iconStart: this.iconStart, mode: this.mode, label: this.label, ref: (el) => (this.inputSearchEl = el), endpoint: "searchUsers", resultsKey: "searchUsers.results", name: this.name, searchParams: {
        limit: this.limit ? this.limit : null,
      }, results: this.results, placeholder: this.placeholder, value: this.value, template: (result) => (index.h("ion-item", { onClick: (event) => this.selectUser(event, result), style: {
          cursor: "pointer",
        } }, index.h("ion-label", null, index.h("h2", null, result.firstName ? result.firstName : "", " ", result.lastName ? result.lastName : ""), index.h("p", null, result.email ? result.email : "No email on file")), index.h("ion-icon", { name: "checkmark-circle" }))) }, index.h("slot", { name: "start" }), index.h("slot", { name: "end" }), index.h("input", { style: {
        opacity: "0",
        height: "0",
        width: "0",
        float: "left",
        margin: "0",
        padding: "0",
      }, type: "text", pattern: this.pattern, value: this.value, required: this.required })));
  }
};
InputSearchUser.style = inputSearchUserCss;

exports.fireenjin_input_search_user = InputSearchUser;
