"use strict";

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

var React = _interopRequireWildcard(require("react"));

var _addonActions = require("@storybook/addon-actions");

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

var _index = require("./index");

var _constants = require("./constants");

var _index2 = require("../styles/index");

var _examplesColors = _interopRequireDefault(require("./examples-colors"));

var _examplesList = _interopRequireDefault(require("./examples-list"));

var _tests$SELECT$tests$M;

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

var size = function size() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.SIZE.default;
  return (0, _addonKnobs.radios)('size', {
    default: _constants.SIZE.default,
    compact: _constants.SIZE.compact
  }, defaultValue);
};

var type = function type() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _index.TYPE.select;
  return (0, _addonKnobs.radios)('type', {
    select: _index.TYPE.select,
    search: _index.TYPE.search
  }, defaultValue);
};

var backspaceRemoves = function backspaceRemoves() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('backspaceRemoves', defaultValue);
};

var clearable = function clearable() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('clearable', defaultValue);
};

var closeOnSelect = function closeOnSelect() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('closeOnSelect', defaultValue);
};

var deleteRemoves = function deleteRemoves() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('deleteRemoves', defaultValue);
};

var disabled = function disabled() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  return (0, _addonKnobs.boolean)('disabled', defaultValue);
};

var error = function error() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  return (0, _addonKnobs.boolean)('error', defaultValue);
};

var escapeClearsValue = function escapeClearsValue() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('escapeClearsValue', defaultValue);
};

var filterOutSelected = function filterOutSelected() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('filterOutSelected', defaultValue);
};

var isLoading = function isLoading() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  return (0, _addonKnobs.boolean)('isLoading', defaultValue);
};

var multi = function multi() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  return (0, _addonKnobs.boolean)('multi', defaultValue);
};

var onBlurResetsInput = function onBlurResetsInput() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('onBlurResetsInput', defaultValue);
};

var onCloseResetsInput = function onCloseResetsInput() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('onCloseResetsInput', defaultValue);
};

var onSelectResetsInput = function onSelectResetsInput() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('onSelectResetsInput', defaultValue);
};

var openOnClick = function openOnClick() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('openOnClick', defaultValue);
};

var required = function required() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('required', defaultValue);
};

var searchable = function searchable() {
  var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return (0, _addonKnobs.boolean)('searchable', defaultValue);
};

var onChange = function onChange() {
  var _console;

  // eslint-disable-next-line no-console
  (_console = console).log.apply(_console, arguments);
};

var onChangeAction = (0, _addonActions.action)('select change');
var CustomValueWrapper = (0, _index2.styled)('span', {
  display: 'inline-flex',
  alignItems: 'center'
});
var CustomValueColor = (0, _index2.styled)('span', function (_ref) {
  var $color = _ref.$color;
  return {
    display: 'inline-block',
    borderRadius: '50%',
    width: '10px',
    height: '10px',
    backgroundColor: $color,
    marginRight: '5px'
  };
});

function CustomOptionLabel(_ref2) {
  var option = _ref2.option,
      _ref2$showColor = _ref2.showColor,
      showColor = _ref2$showColor === void 0 ? false : _ref2$showColor;
  return React.createElement(CustomValueWrapper, null, option.color ? React.createElement(CustomValueColor, {
    $color: option.color
  }) : null, option.id, showColor && " (".concat(option.color, ")"));
}

var options = {
  options: _examplesColors.default,
  labelKey: 'id',
  valueKey: 'color',
  onChange: onChange,
  placeholder: 'Choose a color',
  maxDropdownHeight: '300px'
};

var optionsWithDisabled = _toConsumableArray(_examplesColors.default);

optionsWithDisabled[1] = _objectSpread({}, optionsWithDisabled[1], {
  disabled: true
});

var _default = (_tests$SELECT$tests$M = {}, _defineProperty(_tests$SELECT$tests$M, _examplesList.default.SELECT, function Story1() {
  return React.createElement(_index.StatefulSelect, _extends({}, options, {
    backspaceRemoves: backspaceRemoves(),
    clearable: clearable(),
    closeOnSelect: closeOnSelect(),
    deleteRemoves: deleteRemoves(),
    disabled: disabled(),
    error: error(),
    escapeClearsValue: escapeClearsValue(),
    filterOutSelected: filterOutSelected(),
    isLoading: isLoading(),
    multi: multi(),
    onBlurResetsInput: onBlurResetsInput(),
    onCloseResetsInput: onCloseResetsInput(),
    onSelectResetsInput: onSelectResetsInput(),
    openOnClick: openOnClick(),
    required: required(),
    searchable: searchable(),
    size: size(),
    type: type()
  }, {
    onChange: onChangeAction,
    placeholder: "Check out the `KNOBS` tab to toggle some props" // eslint-disable-next-line jsx-a11y/no-autofocus
    ,
    autoFocus: false
  }));
}), _defineProperty(_tests$SELECT$tests$M, _examplesList.default.MULTI_SELECT, function Story2() {
  return React.createElement(_index.StatefulSelect, _extends({}, options, {
    initialState: {
      value: [_objectSpread({}, _examplesColors.default[0], {
        clearableValue: false
      }), _examplesColors.default[1], _examplesColors.default[3]]
    },
    closeOnSelect: false,
    clearable: false,
    multi: true,
    onChange: onChange
  }));
}), _defineProperty(_tests$SELECT$tests$M, _examplesList.default.SINGLE_SELECT_SEARCH, function Story3() {
  return React.createElement(_index.StatefulSelect, _extends({}, options, {
    options: optionsWithDisabled,
    placeholder: "Start searching",
    type: _index.TYPE.search,
    onChange: onChange
  }));
}), _defineProperty(_tests$SELECT$tests$M, _examplesList.default.MULTI_SELECT_SEARCH, function Story4() {
  return React.createElement(_index.StatefulSelect, _extends({}, options, {
    placeholder: "Start searching",
    type: _index.TYPE.search,
    multi: true,
    onChange: onChange
  }));
}), _defineProperty(_tests$SELECT$tests$M, _examplesList.default.MULTI_SELECT_CUSTOM_LABELS, function Story5() {
  return React.createElement(_index.StatefulSelect, _extends({}, options, {
    initialState: {
      value: [_examplesColors.default[2]]
    },
    type: _index.TYPE.search,
    multi: true,
    onChange: onChange,
    getOptionLabel: function getOptionLabel(_ref3) {
      var option = _ref3.option;
      return React.createElement(CustomOptionLabel, {
        option: option,
        showColor: true
      });
    },
    getValueLabel: function getValueLabel(_ref4) {
      var option = _ref4.option;
      return React.createElement(CustomOptionLabel, {
        option: option
      });
    }
  }));
}), _tests$SELECT$tests$M);

exports.default = _default;