'use strict';

const referenceField = require('./reference-field-1239b0c3.js');
const BaseField = require('./BaseField-381327a9.js');
require('./index-2eea69a0.js');
const index$4 = require('./index-0783d14f.js');
const index = require('./index-1141a245.js');
const FieldGenerator = require('./FieldGenerator-279a646b.js');
const index$3 = require('./index-9d3d3d15.js');
const index$2 = require('./index-9fd84b93.js');
const index$1 = require('./index-61f9621a.js');
const date = require('./date-a24d7714.js');

class NumberField extends BaseField.BaseField {
  constructor(id, title, placeholder, description, step = 1, min = -Infinity, max = Infinity) {
    super(id, 'number');
    this.title = title;
    this.placeholder = placeholder;
    this.description = description;
    this.step = step;
    this.min = min;
    this.max = max;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getDisplayValue(value) {
    return value;
  }
}
NumberField.type = 'number';

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

class RangeField extends BaseField.BaseField {
  constructor(id, title, description, step = 1, min = 0, max = 5) {
    super(id, 'range');
    this.title = title;
    this.description = description;
    this.step = step;
    this.min = min;
    this.max = max;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getDisplayValue(value) {
    return value;
  }
  setInputType(inputType) {
    this.inputType = inputType;
    return this;
  }
}
RangeField.type = 'range';

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

class SectionHeaderField extends BaseField.BaseField {
  constructor(id, header, sectionDescription) {
    super(id, 'sectionHeader');
    this.id = id;
    this.header = header;
    this.sectionDescription = sectionDescription;
  }
}
SectionHeaderField.type = 'sectionHeader';

const render = (field, 
// @ts-ignore
value, 
// @ts-ignore
errors, disabled, onFieldChange, onFieldBlur) => index.h("dvn-field-input-section-header", { disabled: disabled, field: field, onChange: (v) => onFieldChange(field, v), onBlur: () => onFieldBlur(field) });
// register 'sectionHeader' key for json form generations
FieldGenerator.registerField('sectionHeader', render);

function generateFieldModelFromRawData(fieldData) {
  if (!fieldData) {
    return undefined;
  }
  switch (fieldData.type) {
    case date.DateField.type:
      return Object.assign(Object.create(date.DateField.prototype), fieldData);
    case index$4.MultipleChoiceField.type:
      return Object.assign(Object.create(index$4.MultipleChoiceField.prototype), fieldData);
    case NumberField.type:
      return Object.assign(Object.create(NumberField.prototype), fieldData);
    case RangeField.type:
      return Object.assign(Object.create(RangeField.prototype), fieldData);
    case SectionHeaderField.type:
      return Object.assign(Object.create(SectionHeaderField.prototype), fieldData);
    case index$3.SingleChoiceField.type:
      return Object.assign(Object.create(index$3.SingleChoiceField.prototype), fieldData);
    case index$2.SubFormField.type:
      return Object.assign(Object.create(index$2.SubFormField.prototype), fieldData);
    case index$1.TextField.type:
      return Object.assign(Object.create(index$1.TextField.prototype), fieldData);
    case referenceField.ReferenceField.type:
      return Object.assign(Object.create(referenceField.ReferenceField.prototype), fieldData);
    default:
      return Object.assign(Object.create(BaseField.BaseField.prototype), fieldData);
  }
}

exports.NumberField = NumberField;
exports.RangeField = RangeField;
exports.generateFieldModelFromRawData = generateFieldModelFromRawData;
