import { r as registerInstance, i as createEvent, h } from './index-c04b9ed5.js';

const sparkleInputCss = "";

const SparkleInput = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.valueChanged = createEvent(this, "valueChanged", 7);
    this.checkedChanged = 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 (h("div", null, h("ion-item", null, h("ion-label", null, this.label), h("ion-input", { type: this.type, value: this.value, placeholder: this.placeholder, onInput: (event) => this.handleChange(event), required: true }))));
      case 'textarea':
        return (h("div", null, h("ion-item", null, h("ion-label", null, this.label), h("ion-textarea", { value: this.value, placeholder: this.placeholder, onInput: (event) => this.handleChange(event), required: true }))));
      case 'checkbox':
        return (h("div", null, h("ion-item", null, h("ion-checkbox", { slot: "start", checked: this.checked, onChange: (event) => this.handleChange(event) }), h("ion-label", null, this.label))));
      case 'select':
        return (h("div", null, h("ion-item", null, h("ion-select", { value: this.value, placeholder: this.label, onIonChange: event => this.handleChange(event) }, this._options.map(option => (h("ion-select-option", { key: option.value, value: option.value }, option.label)))))));
      default:
        return null;
    }
  }
  static get watchers() { return {
    "options": ["arrayDataWatcher"]
  }; }
};
SparkleInput.style = sparkleInputCss;

export { SparkleInput as sparkle_input };
