"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.groupedSuggestions = exports.disableRemovalOfFirst = exports.default = exports.customSuggestions = exports.basic = void 0;

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

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

var _react = _interopRequireDefault(require("react"));

var _utils = require("../../../.storybook/utils");

var _EmailSelector = _interopRequireDefault(require("./EmailSelector"));

var _typography = require("../typography");

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 defaultEmailSelectorProps = {
  error: '',
  menuFullWidth: true,
  disableRemovalOfFirst: false
};
var _default = {
  component: _EmailSelector.default,
  title: (0, _utils.addStoryInGroup)(_utils.LOW_LEVEL_BLOCKS, 'Form elements/EmailSelector'),
  parameters: {}
};
exports.default = _default;
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;

var validator = function validator(_ref) {
  var email = _ref.email;
  return EMAIL_REGEX.test(email);
};

var suggestions = [{
  email: 'david.brent@dundermiflin.com',
  label: 'David Brent'
}, {
  email: 'david.wallace@dundermiflin.com',
  label: 'David Wallace'
}, {
  email: 'alan.brand@dundermiflin.com',
  label: 'Alan Brand'
}, {
  email: 'robert.mifflin@dundermiflin.com',
  label: 'Robert Mifflin'
}, {
  email: 'robert.dunder@dundermiflin.com',
  label: 'Robert Dunder'
}];

var basic = function basic(args) {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, (0, _extends2.default)({}, args, {
    validator: validator,
    defaultSelection: [suggestions[0]],
    suggestions: suggestions
  }));
};

exports.basic = basic;
basic.args = defaultEmailSelectorProps;

var groupedSuggestions = function groupedSuggestions(args) {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, (0, _extends2.default)({}, args, {
    validator: validator,
    suggestions: {
      davids: [{
        email: 'david.brent@dundermiflin.com',
        label: 'David Brent'
      }, {
        email: 'david.wallace@dundermiflin.com',
        label: 'David Wallace'
      }],
      roberts: [{
        email: 'robert.mifflin@dundermiflin.com',
        label: 'Robert Mifflin'
      }, {
        email: 'robert.dunder@dundermiflin.com',
        label: 'Robert Dunder'
      }]
    }
  }));
};

exports.groupedSuggestions = groupedSuggestions;
groupedSuggestions.args = defaultEmailSelectorProps;

var customSuggestions = function customSuggestions(args) {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, (0, _extends2.default)({}, args, {
    validator: validator,
    suggestions: suggestions,
    renderSuggestion: function renderSuggestion(_ref2) {
      var suggestion = _ref2.suggestion,
          selected = _ref2.selected;
      return /*#__PURE__*/_react.default.createElement(_typography.TextBody, {
        padding: 2,
        borderTopWidth: selected ? 1 : 0,
        borderBottomWidth: selected ? 1 : 0
      }, suggestion.email);
    }
  }));
};

exports.customSuggestions = customSuggestions;
customSuggestions.args = defaultEmailSelectorProps;

var disableRemovalOfFirst = function disableRemovalOfFirst(args) {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, (0, _extends2.default)({}, args, {
    validator: validator,
    defaultSelection: [suggestions[0]],
    suggestions: suggestions
  }));
};

exports.disableRemovalOfFirst = disableRemovalOfFirst;
disableRemovalOfFirst.args = _objectSpread(_objectSpread({}, defaultEmailSelectorProps), {}, {
  disableRemovalOfFirst: true
});