import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _extends from "@babel/runtime/helpers/extends";

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) { _defineProperty(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; }

import React from 'react';
import { addStoryInGroup, LOW_LEVEL_BLOCKS } from '../../../.storybook/utils';
import EmailSelector from './EmailSelector';
import { TextBody } from '../typography';
var defaultEmailSelectorProps = {
  error: '',
  menuFullWidth: true,
  disableRemovalOfFirst: false
};
export default {
  component: EmailSelector,
  title: addStoryInGroup(LOW_LEVEL_BLOCKS, 'Form elements/EmailSelector'),
  parameters: {}
};
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'
}];
export var basic = function basic(args) {
  return /*#__PURE__*/React.createElement(EmailSelector, _extends({}, args, {
    validator: validator,
    defaultSelection: [suggestions[0]],
    suggestions: suggestions
  }));
};
basic.args = defaultEmailSelectorProps;
export var groupedSuggestions = function groupedSuggestions(args) {
  return /*#__PURE__*/React.createElement(EmailSelector, _extends({}, 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'
      }]
    }
  }));
};
groupedSuggestions.args = defaultEmailSelectorProps;
export var customSuggestions = function customSuggestions(args) {
  return /*#__PURE__*/React.createElement(EmailSelector, _extends({}, args, {
    validator: validator,
    suggestions: suggestions,
    renderSuggestion: function renderSuggestion(_ref2) {
      var suggestion = _ref2.suggestion,
          selected = _ref2.selected;
      return /*#__PURE__*/React.createElement(TextBody, {
        padding: 2,
        borderTopWidth: selected ? 1 : 0,
        borderBottomWidth: selected ? 1 : 0
      }, suggestion.email);
    }
  }));
};
customSuggestions.args = defaultEmailSelectorProps;
export var disableRemovalOfFirst = function disableRemovalOfFirst(args) {
  return /*#__PURE__*/React.createElement(EmailSelector, _extends({}, args, {
    validator: validator,
    defaultSelection: [suggestions[0]],
    suggestions: suggestions
  }));
};
disableRemovalOfFirst.args = _objectSpread(_objectSpread({}, defaultEmailSelectorProps), {}, {
  disableRemovalOfFirst: true
});