"use strict";

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

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

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

var _addonKnobs = require("@storybook/addon-knobs");

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

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

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

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() {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, {
    error: (0, _addonKnobs.text)('Error', ''),
    validator: validator,
    defaultSelection: [suggestions[0]],
    suggestions: suggestions
  });
};

exports.basic = basic;

var groupedSuggestions = function groupedSuggestions() {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, {
    error: (0, _addonKnobs.text)('Error', ''),
    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;

var customSuggestions = function customSuggestions() {
  return /*#__PURE__*/_react.default.createElement(_EmailSelector.default, {
    error: (0, _addonKnobs.text)('Error', ''),
    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;