"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.MixinsSpacing = exports.FreeFormMultiple = exports.FreeFormSingle = exports.SecondaryTextMultiple = exports.SecondaryTextSingle = exports.CustomItemsMultiple = exports.CustomItemsSingle = exports.LargeMultiple = exports.LargeSingle = exports.Multiple = exports.Single = exports["default"] = void 0;

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

var _listSelector = require("./list-selector.component");

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

var _paddingChecker = require("../../../mixins/spacing/story-support/padding-checker");

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

var _box = require("../../../primitives/box");

var _text = require("../../typography/text");

var _span = require("../../typography/span");

var _textInput = require("../text-input");

var _icon = require("../../icon");

var _unstyledButton = require("../../behaviors/unstyled-button");

var _listSelector2 = _interopRequireDefault(require("./list-selector.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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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 _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: _listSelector.ListSelector,
  title: 'Components/Inputs/ListSelector',
  parameters: {
    docs: {
      page: _listSelector2["default"]
    }
  }
};
exports["default"] = _default;
var items = [{
  id: 'APPLE',
  label: 'Apple'
}, {
  id: 'PEAR',
  label: 'Pear'
}, {
  id: 'EGGPLANT',
  label: 'Yucky eggplant',
  disabled: true
}, {
  id: 'KIWI',
  label: 'Kiwi'
}];
var taxonomicalNames = {
  APPLE: 'Malus domestica',
  PEAR: 'Pyrus communis',
  EGGPLANT: 'Solanium melongena',
  KIWI: 'Actinidia deliciosa'
};

var DemoSelectionSummary = function DemoSelectionSummary(_ref) {
  var selectedIds = _ref.selectedIds,
      _ref$customValue = _ref.customValue,
      customValue = _ref$customValue === void 0 ? '' : _ref$customValue;
  return /*#__PURE__*/_react["default"].createElement(_text.Text, {
    "aria-live": "polite",
    bold: true,
    spacing: "mt1",
    colorName: "greyscale-dark"
  }, selectedIds.length > 0 && /*#__PURE__*/_react["default"].createElement("span", null, "You selected", ' ', selectedIds.map(function (id) {
    return id === 'CUSTOM' ? "CUSTOM(".concat(customValue, ")") : id;
  }).join()));
};

var Single = function Single() {
  var _useState = (0, _react.useState)([]),
      _useState2 = _slicedToArray(_useState, 2),
      selectedIds = _useState2[0],
      setSelectedIds = _useState2[1];

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: items,
    name: "favorite-fruit-single",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.Single = Single;

var Multiple = function Multiple() {
  var _useState3 = (0, _react.useState)([]),
      _useState4 = _slicedToArray(_useState3, 2),
      selectedIds = _useState4[0],
      setSelectedIds = _useState4[1];

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: items,
    name: "favorite-fruit-multi",
    multiSelect: true,
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.Multiple = Multiple;

var LargeSingle = function LargeSingle() {
  var _useState5 = (0, _react.useState)([]),
      _useState6 = _slicedToArray(_useState5, 2),
      selectedIds = _useState6[0],
      setSelectedIds = _useState6[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: ['ph1', 'pv2']
      }, /*#__PURE__*/_react["default"].createElement(_span.Span, {
        bold: true,
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black',
        fontSize: "f2"
      }, item.label))
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-large-single",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.LargeSingle = LargeSingle;

var LargeMultiple = function LargeMultiple() {
  var _useState7 = (0, _react.useState)([]),
      _useState8 = _slicedToArray(_useState7, 2),
      selectedIds = _useState8[0],
      setSelectedIds = _useState8[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: ['ph1', 'pv2']
      }, /*#__PURE__*/_react["default"].createElement(_span.Span, {
        bold: true,
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black',
        fontSize: "f2"
      }, item.label))
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-large-multiple",
    value: selectedIds,
    onChange: setSelectedIds,
    multiSelect: true
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.LargeMultiple = LargeMultiple;

var CustomItemsSingle = function CustomItemsSingle() {
  var _useState9 = (0, _react.useState)([]),
      _useState10 = _slicedToArray(_useState9, 2),
      selectedIds = _useState10[0],
      setSelectedIds = _useState10[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: ['ph2', 'pt2']
      }, /*#__PURE__*/_react["default"].createElement(_text.Text, {
        bold: true,
        spacing: "mv0",
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, item.label), /*#__PURE__*/_react["default"].createElement(_text.Text, {
        fontSize: "f1",
        spacing: "mt1",
        italic: true,
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, taxonomicalNames[String(item.id)]))
    });
  }).concat({
    id: 'nonOptionRow',
    isNonOptionRow: true,
    label: /*#__PURE__*/_react["default"].createElement(_unstyledButton.UnstyledButton, {
      stacked: "row",
      grow: 1,
      justify: "space-between",
      align: "center",
      insetFocus: true,
      spacing: ['pv2', 'pl4', 'pr1']
    }, /*#__PURE__*/_react["default"].createElement(_text.Text, {
      spacing: "m0",
      bold: true,
      fontSize: "f1"
    }, "Show more"), /*#__PURE__*/_react["default"].createElement(_icon.ChevronDown, null))
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-custom-single",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.CustomItemsSingle = CustomItemsSingle;

var CustomItemsMultiple = function CustomItemsMultiple() {
  var _useState11 = (0, _react.useState)([]),
      _useState12 = _slicedToArray(_useState11, 2),
      selectedIds = _useState12[0],
      setSelectedIds = _useState12[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: ['ph2', 'pt2']
      }, /*#__PURE__*/_react["default"].createElement(_text.Text, {
        bold: true,
        spacing: "mv0",
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, item.label), /*#__PURE__*/_react["default"].createElement(_text.Text, {
        fontSize: "f1",
        spacing: "mt1",
        italic: true,
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, taxonomicalNames[String(item.id)]))
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-custom-multiple",
    value: selectedIds,
    onChange: setSelectedIds,
    multiSelect: true
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.CustomItemsMultiple = CustomItemsMultiple;

var SecondaryTextSingle = function SecondaryTextSingle() {
  var _useState13 = (0, _react.useState)([]),
      _useState14 = _slicedToArray(_useState13, 2),
      selectedIds = _useState14[0],
      setSelectedIds = _useState14[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: "pv1",
        stacked: "row",
        justify: "space-between",
        grow: 1
      }, /*#__PURE__*/_react["default"].createElement(_span.Span, {
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, item.label), /*#__PURE__*/_react["default"].createElement(_span.Span, {
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black',
        spacing: "pr2"
      }, taxonomicalNames[String(item.id)]))
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-secondary-single",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.SecondaryTextSingle = SecondaryTextSingle;

var SecondaryTextMultiple = function SecondaryTextMultiple() {
  var _useState15 = (0, _react.useState)([]),
      _useState16 = _slicedToArray(_useState15, 2),
      selectedIds = _useState16[0],
      setSelectedIds = _useState16[1];

  var customItems = items.map(function (item) {
    return _objectSpread(_objectSpread({}, item), {}, {
      label: /*#__PURE__*/_react["default"].createElement(_box.Box, {
        spacing: "pv1",
        stacked: "row",
        justify: "space-between",
        grow: 1
      }, /*#__PURE__*/_react["default"].createElement(_span.Span, {
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black'
      }, item.label), /*#__PURE__*/_react["default"].createElement(_span.Span, {
        colorName: item.disabled ? 'greyscale-dark' : 'greyscale-black',
        spacing: "pr2"
      }, taxonomicalNames[String(item.id)]))
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: customItems,
    name: "favorite-fruit-secondary-multiple",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds
  }));
};

exports.SecondaryTextMultiple = SecondaryTextMultiple;

var FreeFormSingle = function FreeFormSingle() {
  var _useState17 = (0, _react.useState)([]),
      _useState18 = _slicedToArray(_useState17, 2),
      selectedIds = _useState18[0],
      setSelectedIds = _useState18[1];

  var _useState19 = (0, _react.useState)(),
      _useState20 = _slicedToArray(_useState19, 2),
      customValue = _useState20[0],
      setCustomValue = _useState20[1];

  var itemsWithFreeForm = items.concat({
    id: 'CUSTOM',
    label: /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
      grow: 1,
      spacing: "mt1",
      isEmbeddable: true,
      fontSize: "f1",
      label: "Other (written below)",
      placeholder: "Something delicious",
      onChange: setCustomValue,
      value: customValue
    })
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: itemsWithFreeForm,
    name: "favorite-fruit-free-form-single",
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds,
    customValue: customValue
  }));
};

exports.FreeFormSingle = FreeFormSingle;

var FreeFormMultiple = function FreeFormMultiple() {
  var _useState21 = (0, _react.useState)([]),
      _useState22 = _slicedToArray(_useState21, 2),
      selectedIds = _useState22[0],
      setSelectedIds = _useState22[1];

  var _useState23 = (0, _react.useState)(),
      _useState24 = _slicedToArray(_useState23, 2),
      customValue = _useState24[0],
      setCustomValue = _useState24[1];

  var itemsWithFreeForm = items.concat({
    id: 'CUSTOM',
    label: /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
      grow: 1,
      spacing: "mt1",
      isEmbeddable: true,
      fontSize: "f1",
      label: "Other (written below)",
      placeholder: "Something delicious",
      onChange: setCustomValue,
      value: customValue
    })
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_listSelector.ListSelector, {
    label: "Favorite Fruit",
    items: itemsWithFreeForm,
    name: "favorite-fruit-free-form-multi",
    multiSelect: true,
    value: selectedIds,
    onChange: setSelectedIds
  }), /*#__PURE__*/_react["default"].createElement(DemoSelectionSummary, {
    selectedIds: selectedIds,
    customValue: customValue
  }));
};

exports.FreeFormMultiple = FreeFormMultiple;

var MixinsSpacing = function MixinsSpacing() {
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_marginChecker.MarginChecker, {
    Component: _listSelector.ListSelector,
    label: "Favorite Fruit",
    name: "mixins-spacing",
    items: [items[0]],
    value: []
  }), /*#__PURE__*/_react["default"].createElement(_paddingChecker.PaddingChecker, {
    Component: _listSelector.ListSelector,
    label: "Favorite Fruit",
    items: [items[0]],
    value: []
  }));
};

exports.MixinsSpacing = MixinsSpacing;

var MixinsStackee = function MixinsStackee() {
  return /*#__PURE__*/_react["default"].createElement(_stackeeChecker.StackeeChecker, {
    Component: _listSelector.ListSelector,
    label: "Favorite Fruit",
    name: "mixins-stackee",
    items: [items[0]],
    value: []
  });
};

exports.MixinsStackee = MixinsStackee;