'use strict';

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

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

const sparkleInputCss = "";

const SparkleInput = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.valueChanged = index.createEvent(this, "valueChanged", 7);
    this.checkedChanged = index.createEvent(this, "checkedChanged", 7);
  }
  arrayDataWatcher(newValue) {
    if (typeof newValue === 'string') {
      this._options = JSON.parse(newValue);
    }
    else {
      this._options = newValue;
    }
  }
  componentWillLoad() {
    if (this.type == 'select') {
      this.arrayDataWatcher(this.options);
    }
  }
  handleChange(event) {
    const value = this.type === 'checkbox' ? event.target.checked : event.target.value;
    this.value = value;
    this.valueChanged.emit(value);
    if (this.type === 'checkbox') {
      this.checkedChanged.emit(value);
    }
  }
  render() {
    switch (this.type) {
      case 'text'    :
        return (index.h("div", null, index.h("ion-item", null, index.h("ion-label", null, this.label), index.h("ion-input", { type: this.type, value: this.value, placeholder: this.placeholder, onInput: (event) => this.handleChange(event), required: true }))));
      case 'textarea':
        return (index.h("div", null, index.h("ion-item", null, index.h("ion-label", null, this.label), index.h("ion-textarea", { value: this.value, placeholder: this.placeholder, onInput: (event) => this.handleChange(event), required: true }))));
      case 'checkbox':
        return (index.h("div", null, index.h("ion-item", null, index.h("ion-checkbox", { slot: "start", checked: this.checked, onChange: (event) => this.handleChange(event) }), index.h("ion-label", null, this.label))));
      case 'select':
        return (index.h("div", null, index.h("ion-item", null, index.h("ion-select", { value: this.value, placeholder: this.label, onIonChange: event => this.handleChange(event) }, this._options.map(option => (index.h("ion-select-option", { key: option.value, value: option.value }, option.label)))))));
      default:
        return null;
    }
  }
  static get watchers() { return {
    "options": ["arrayDataWatcher"]
  }; }
};
SparkleInput.style = sparkleInputCss;

exports.sparkle_input = SparkleInput;
