'use strict';

const index = require('./index-ce58ddc5.js');
const BaseField = require('./BaseField-d019ade6.js');

const fieldTypeMap = new Map();
function registerField(fieldType, inputGenerator) {
  fieldTypeMap.set(fieldType, inputGenerator);
}
function generateField(field, value, errors = [], disabled, onFieldChange, onFieldBlur) {
  if (field.render) {
    return field.render(field, value, errors, disabled, onFieldChange, onFieldBlur);
  }
  if (field.customViewTag) {
    const Tag = field.customViewTag;
    return index.h(Tag, { disabled: disabled, field: field, errors: errors, onChange: onFieldChange, onBlur: onFieldBlur, value: value });
  }
  const generator = fieldTypeMap.get(field.type);
  if (generator) {
    return generator(field, value, errors, disabled, onFieldChange, onFieldBlur);
  }
  return null;
}

class TextField extends BaseField.BaseField {
  constructor(id, title, placeholder, description, inputType, lines = 1, linesMax = 1) {
    super(id, 'text');
    this.format = 'raw';
    this.id = id;
    this.title = title;
    this.placeholder = placeholder;
    this.description = description;
    this.inputType = inputType;
    this.lines = lines;
    this.linesMax = linesMax;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getDisplayValue(value) {
    return value;
  }
  setInputType(inputType) {
    this.inputType = inputType;
    return this;
  }
  setFormat(format) {
    this.format = format;
    return this;
  }
  setLines(lines) {
    this.lines = lines;
    return this;
  }
  setLinesMax(linesMax) {
    this.linesMax = linesMax;
    return this;
  }
  setAutoComplete(autoComplete) {
    this.autoComplete = autoComplete;
    return this;
  }
}
TextField.type = 'text';

// component generator
const render = (field, value, errors, disabled, onFieldChange, onFieldBlur) => index.h("dvn-field-input-text", { disabled: disabled, field: field, errors: errors, onChange: (e) => {
    e.stopImmediatePropagation();
    onFieldChange(field, e.detail);
  }, onBlur: () => onFieldBlur(field), value: value });
// register 'text' field for json form generations
registerField('text', render);

exports.TextField = TextField;
exports.generateField = generateField;
exports.registerField = registerField;
