'use strict';

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

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

exports.Enum = Enum;

var _uniq = require('lodash/uniq');

var _uniq2 = _interopRequireDefault(_uniq);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function Enum() {
  var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  var type = void 0;
  var choices = values;

  if (obj.type && Array.isArray(obj.type)) {
    if (obj.type.includes(Boolean)) choices.push('');
    type = (0, _uniq2.default)([].concat((0, _toConsumableArray3.default)(obj.type), [String]));
  } else if (obj.type) {
    if (obj.type === Boolean) choices.push('');
    type = [String, obj.type];
  } else {
    type = String;
  }

  return (0, _extends3.default)({}, obj, {
    choices: choices,
    type: type,
    validator: function validator(value) {
      return typeof value !== 'string' || choices.includes(value);
    }
  });
}

Enum.Size = Enum(['mini', 'tiny', 'small', 'medium', 'large', 'big', 'huge', 'massive']);
Enum.Color = Enum(['red', 'orange', 'yellow', 'olive', 'green', 'teal', 'blue', 'violet', 'purple', 'pink', 'brown', 'grey', 'black']);