"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "Panel", {
  enumerable: true,
  get: function get() {
    return _panel["default"];
  }
});
exports.toggle = exports.textField = exports.radio = exports.numberFields = exports.numberField = exports.dropdown = exports.checkboxes = exports.checkbox = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _panel = _interopRequireDefault(require("./panel"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var textField = function textField(label) {
  var isConfigProperty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  return {
    label: label,
    type: 'textField',
    isConfigProperty: isConfigProperty
  };
};

exports.textField = textField;

var toggle = function toggle(label) {
  var isConfigProperty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  return {
    type: 'toggle',
    label: label,
    isConfigProperty: isConfigProperty
  };
};

exports.toggle = toggle;

var toChoice = function toChoice(opt) {
  if (typeof opt === 'string') {
    return {
      label: opt,
      value: opt
    };
  } else {
    return opt;
  }
};

var radio = function radio() {
  var args = Array.prototype.slice.call(arguments);

  var _args = (0, _slicedToArray2["default"])(args, 3),
      label = _args[0],
      choices = _args[1],
      _args$ = _args[2],
      isConfigProperty = _args$ === void 0 ? false : _args$;

  return {
    type: 'radio',
    label: label,
    choices: choices && choices.map(function (o) {
      return toChoice(o);
    }),
    isConfigProperty: isConfigProperty
  };
};

exports.radio = radio;

var dropdown = function dropdown(label, choices) {
  var isConfigProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  return {
    type: 'dropdown',
    label: label,
    choices: choices,
    isConfigProperty: isConfigProperty
  };
};

exports.dropdown = dropdown;

var numberField = function numberField(label, options) {
  var isConfigProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  return _objectSpread(_objectSpread({}, options), {}, {
    label: label,
    type: 'numberField',
    isConfigProperty: isConfigProperty
  });
};

exports.numberField = numberField;

var numberFields = function numberFields(label, fields) {
  var isConfigProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  Object.keys(fields).map(function (key) {
    fields[key] = numberField(fields[key].label, fields[key], isConfigProperty);
  });
  return {
    type: 'numberFields',
    label: label,
    fields: fields
  };
};

exports.numberFields = numberFields;

var checkbox = function checkbox(label, settings) {
  var isConfigProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  return _objectSpread(_objectSpread({}, settings), {}, {
    label: label,
    type: 'checkbox',
    isConfigProperty: isConfigProperty
  });
};

exports.checkbox = checkbox;

var checkboxes = function checkboxes(label, choices) {
  var isConfigProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  Object.keys(choices).map(function (key) {
    choices[key] = checkbox(choices[key].label, choices[key], isConfigProperty);
  });
  return {
    type: 'checkboxes',
    label: label,
    choices: choices
  };
};

exports.checkboxes = checkboxes;
//# sourceMappingURL=index.js.map