"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MixinsStackee = exports.MixinsMarginOnlySpacing = exports.UndefinedValue = exports.LargeWithLabel = exports.WithLabel = exports.ErrorBool = exports.PreSelectedValue = exports.DisabledOption = exports.Disabled = exports.NormalNoPlaceholder = exports.Large = exports.Default = exports["default"] = void 0;

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

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

var _select = require("./select.component");

var _option = require("./option");

var _primitives = require("../../../primitives");

var _actions = require("../../actions");

var _marginChecker = require("../../../mixins/spacing/story-support/margin-checker");

var _stackeeChecker = require("../../../mixins/stackee/story-support/stackee-checker");

var _select2 = _interopRequireDefault(require("./select.mdx"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var _default = {
  component: _select.Select,
  title: 'Components/Inputs/Select',
  parameters: {
    docs: {
      page: _select2["default"]
    }
  }
};
exports["default"] = _default;

var withStorybookAction = function withStorybookAction(onChange) {
  return function (value) {
    (0, _addonActions.action)('onChange')(value);
    onChange(value);
  };
};

var DEFAULT_PROPS = {
  label: 'Label',
  hideLabel: true,
  placeholder: 'Select something'
};

var Default = function Default() {
  var _useState = (0, _react.useState)(undefined),
      _useState2 = _slicedToArray(_useState, 2),
      value = _useState2[0],
      setValue = _useState2[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.Default = Default;

var Large = function Large() {
  var _useState3 = (0, _react.useState)('1'),
      _useState4 = _slicedToArray(_useState3, 2),
      value = _useState4[0],
      setValue = _useState4[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    onChange: withStorybookAction(setValue),
    value: value,
    large: true
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.Large = Large;

var NormalNoPlaceholder = function NormalNoPlaceholder() {
  var _useState5 = (0, _react.useState)(undefined),
      _useState6 = _slicedToArray(_useState5, 2),
      value = _useState6[0],
      setValue = _useState6[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    placeholder: undefined,
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.NormalNoPlaceholder = NormalNoPlaceholder;

var Disabled = function Disabled() {
  var _useState7 = (0, _react.useState)(undefined),
      _useState8 = _slicedToArray(_useState7, 2),
      value = _useState8[0],
      setValue = _useState8[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({
    disabled: true
  }, DEFAULT_PROPS, {
    placeholder: "You can't select something",
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.Disabled = Disabled;

var DisabledOption = function DisabledOption() {
  var _useState9 = (0, _react.useState)(undefined),
      _useState10 = _slicedToArray(_useState9, 2),
      value = _useState10[0],
      setValue = _useState10[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    placeholder: "Second option is disabled",
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2,
    disabled: true
  }, "Second option"));
};

exports.DisabledOption = DisabledOption;

var PreSelectedValue = function PreSelectedValue() {
  var _useState11 = (0, _react.useState)('three'),
      _useState12 = _slicedToArray(_useState11, 2),
      value = _useState12[0],
      setValue = _useState12[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    placeholder: "Select something",
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "one"
  }, "One"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "two"
  }, "Two"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "three"
  }, "Three"));
};

exports.PreSelectedValue = PreSelectedValue;

var ErrorBool = function ErrorBool() {
  var _useState13 = (0, _react.useState)(undefined),
      _useState14 = _slicedToArray(_useState13, 2),
      value = _useState14[0],
      setValue = _useState14[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    error: true,
    placeholder: "Select something",
    onChange: withStorybookAction(setValue),
    value: value
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.ErrorBool = ErrorBool;

var WithLabel = function WithLabel() {
  var _useState15 = (0, _react.useState)(undefined),
      _useState16 = _slicedToArray(_useState15, 2),
      value = _useState16[0],
      setValue = _useState16[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    onChange: withStorybookAction(setValue),
    value: value,
    hideLabel: false
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.WithLabel = WithLabel;

var LargeWithLabel = function LargeWithLabel() {
  var _useState17 = (0, _react.useState)(undefined),
      _useState18 = _slicedToArray(_useState17, 2),
      value = _useState18[0],
      setValue = _useState18[1];

  return /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    onChange: withStorybookAction(setValue),
    value: value,
    hideLabel: false,
    large: true
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 1
  }, "First option"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: 2
  }, "Second option"));
};

exports.LargeWithLabel = LargeWithLabel;

var UndefinedValue = function UndefinedValue() {
  var _useState19 = (0, _react.useState)('A'),
      _useState20 = _slicedToArray(_useState19, 2),
      value = _useState20[0],
      setValue = _useState20[1];

  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "row",
    align: "center",
    justify: "start"
  }, /*#__PURE__*/_react["default"].createElement(_select.Select, _extends({}, DEFAULT_PROPS, {
    onChange: withStorybookAction(setValue),
    value: value,
    hideLabel: true,
    grow: 1
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "A"
  }, "A"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "B"
  }, "B"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "C"
  }, "C")), /*#__PURE__*/_react["default"].createElement(_actions.TertiaryButton, {
    onClick: function onClick() {
      setValue(undefined);
    },
    spacing: "ml1"
  }, "Reset value to undefined"));
};

exports.UndefinedValue = UndefinedValue;

var MixinsMarginOnlySpacing = function MixinsMarginOnlySpacing() {
  return /*#__PURE__*/_react["default"].createElement(_marginChecker.MarginChecker, _extends({
    Component: _select.Select
  }, DEFAULT_PROPS, {
    onChange: (0, _addonActions.action)('onChange'),
    value: undefined
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "A"
  }, "A"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "B"
  }, "B"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "C"
  }, "C"));
};

exports.MixinsMarginOnlySpacing = MixinsMarginOnlySpacing;

var MixinsStackee = function MixinsStackee() {
  return /*#__PURE__*/_react["default"].createElement(_stackeeChecker.StackeeChecker, _extends({
    Component: _select.Select
  }, DEFAULT_PROPS, {
    onChange: (0, _addonActions.action)('onChange'),
    value: undefined
  }), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "A"
  }, "A"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "B"
  }, "B"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "C"
  }, "C"));
};

exports.MixinsStackee = MixinsStackee;