"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.Checkboxes = exports.Small = exports.FreeformTextItemError = exports.FreeformTextItem = exports.LargeAmountsOfText = exports.SecondaryLabels = exports.CustomItemContent = exports.DisabledHiddenLabel = exports.LargeHiddenLabel = exports.WithLabel = exports["default"] = void 0;

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

var _randomstring = _interopRequireDefault(require("randomstring"));

var _lodash = require("lodash");

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

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

var _selectorItem = require("./selector-item");

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

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

var _selectorItemWithInput = require("./selector-item-with-input");

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

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

var _selector = _interopRequireDefault(require("./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 _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: _index.Selector,
  title: 'Forms/Selector',
  parameters: {
    docs: {
      page: _selector["default"]
    }
  }
};
exports["default"] = _default;

var ExampleRow = function ExampleRow() {
  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "column",
    spacing: ['ph1', 'pt2']
  }, /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    bold: true,
    spacing: "mv0"
  }, "CIBC Everyday Savings Account"), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    fontSize: "f1",
    spacing: "mt1"
  }, "Ending in 1234"));
};

var WithLabel = function WithLabel() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    label: "Choose one",
    stateful: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two"
  }));
};

exports.WithLabel = WithLabel;

var LargeHiddenLabel = function LargeHiddenLabel() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    stateful: true,
    size: "lg",
    label: "Pick One",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two"
  }));
};

exports.LargeHiddenLabel = LargeHiddenLabel;

var DisabledHiddenLabel = function DisabledHiddenLabel() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    stateful: true,
    label: "Pick Something",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two",
    disabled: true
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-three",
    label: "Third choice",
    value: "option-three",
    disabled: true,
    noInput: true
  }));
};

exports.DisabledHiddenLabel = DisabledHiddenLabel;

var CustomItemContent = function CustomItemContent() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    stateful: true,
    label: "You can't see this",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    value: "option-one",
    label: "option one",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(ExampleRow, null)), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    value: "option-two",
    label: "option two",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(ExampleRow, null)));
};

exports.CustomItemContent = CustomItemContent;

var SecondaryLabels = function SecondaryLabels() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    stateful: true,
    label: "Label for the selector"
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "One",
    value: 1
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Two",
    secondaryLabel: "Secondary",
    value: 2
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-three",
    label: "Three",
    secondaryLabel: "Secondary label with a very long description",
    value: 3
  }));
};

exports.SecondaryLabels = SecondaryLabels;

var LargeAmountsOfText = function LargeAmountsOfText() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    onChange: (0, _addonActions.action)('onChange'),
    stateful: true,
    label: "Some options",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    value: "option-one",
    label: "A fancy bank name that is quite long",
    hideLabel: true
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "column",
    spacing: ['ph1', 'pt2']
  }, /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    bold: true,
    spacing: "mv0"
  }, "A fancy bank name that is quite long"), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    fontSize: "f1",
    spacing: "mt1"
  }, "fake text fake text fake text fake text fake text fake text fake text fake text fake text fake text fake text"))), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    value: "option-two",
    label: "fake text fake text fake text fake text fake text fake text fake text fake text fake text fake text fake text"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-three",
    value: "option-three",
    label: "fake"
  }));
};

exports.LargeAmountsOfText = LargeAmountsOfText;

var FreeformTextItem = function FreeformTextItem() {
  var CheckedValuesForRadioDemo = function CheckedValuesForRadioDemo() {
    var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));

    var _useState = (0, _react.useState)('vanilla'),
        _useState2 = _slicedToArray(_useState, 2),
        selected = _useState2[0],
        setSelected = _useState2[1];

    var _useState3 = (0, _react.useState)(),
        _useState4 = _slicedToArray(_useState3, 2),
        inputValue = _useState4[0],
        setInputValue = _useState4[1];

    return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
      name: demoId,
      onChange: function onChange(v) {
        setSelected(v);
        (0, _addonActions.action)('onChange')(v);
      },
      label: "With freeform text",
      hideLabel: true
    }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "vanilla",
      label: "\uD83C\uDF66 Vanilla",
      value: "vanilla",
      checked: selected === 'vanilla'
    }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "ice-cream-chocolate",
      label: "\uD83C\uDF6B Chocolate",
      value: "chocolate",
      checked: selected === 'chocolate'
    }), /*#__PURE__*/_react["default"].createElement(_selectorItemWithInput.SelectorItemWithInput, {
      id: "other",
      label: "Other (written below)",
      value: "other",
      checked: selected === 'other',
      inputValue: inputValue,
      onInputChange: function onInputChange(value) {
        (0, _addonActions.action)('onInputChange');
        setInputValue(value);
      },
      inputProps: {
        placeholder: 'Something delicious'
      }
    }));
  };

  return /*#__PURE__*/_react["default"].createElement(CheckedValuesForRadioDemo, null);
};

exports.FreeformTextItem = FreeformTextItem;

var FreeformTextItemError = function FreeformTextItemError() {
  var CheckedValuesForRadioDemo = function CheckedValuesForRadioDemo() {
    var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));

    var _useState5 = (0, _react.useState)('vanilla'),
        _useState6 = _slicedToArray(_useState5, 2),
        selected = _useState6[0],
        setSelected = _useState6[1];

    var _useState7 = (0, _react.useState)('Something that is not valid'),
        _useState8 = _slicedToArray(_useState7, 2),
        inputValue = _useState8[0],
        setInputValue = _useState8[1];

    return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
      name: demoId,
      onChange: function onChange(v) {
        setSelected(v);
        (0, _addonActions.action)('onChange')(v);
      },
      label: "With error on selector",
      hideLabel: true
    }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "vanilla",
      label: "\uD83C\uDF66 Vanilla",
      value: "vanilla",
      checked: selected === 'vanilla'
    }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "ice-cream-chocolate",
      label: "\uD83C\uDF6B Chocolate",
      value: "chocolate",
      checked: selected === 'chocolate'
    }), /*#__PURE__*/_react["default"].createElement(_selectorItemWithInput.SelectorItemWithInput, {
      id: "other",
      label: "Other (written below)",
      value: "other",
      checked: selected === 'other',
      inputValue: inputValue,
      onInputChange: function onInputChange(value) {
        (0, _addonActions.action)('onInputChange');
        setInputValue(value);
      },
      inputProps: {
        placeholder: 'Something delicious'
      },
      inputError: "Input value is invalid"
    }));
  };

  return /*#__PURE__*/_react["default"].createElement(CheckedValuesForRadioDemo, null);
};

exports.FreeformTextItemError = FreeformTextItemError;

var Small = function Small() {
  var CheckedValuesForCheckboxDemo = function CheckedValuesForCheckboxDemo() {
    var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));

    var _useState9 = (0, _react.useState)(['chocolate', 'vanilla']),
        _useState10 = _slicedToArray(_useState9, 2),
        selected = _useState10[0],
        setSelected = _useState10[1];

    return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
      name: demoId,
      type: "checkbox",
      size: "sm",
      onChange: function onChange(v) {
        if (selected.includes(v)) {
          var newSelected = (0, _lodash.remove)(selected, function (item) {
            return v !== item;
          });
          setSelected(newSelected);
        } else {
          var _newSelected = (0, _lodash.concat)(selected, v);

          setSelected(_newSelected);
        }

        (0, _addonActions.action)('onChange')(Array.isArray(v) ? v.join(', ') : v);
      },
      label: "Small",
      hideLabel: true
    }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "chocolate",
      label: "Chocolate",
      value: "chocolate",
      checked: selected.includes('chocolate')
    }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "vanilla",
      label: "Vanilla",
      value: "vanilla",
      checked: selected.includes('vanilla')
    }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
      id: "strawberry",
      label: "Strawberry",
      value: "strawberry",
      checked: selected.includes('strawberry')
    }));
  };

  return /*#__PURE__*/_react["default"].createElement(CheckedValuesForCheckboxDemo, null);
};

exports.Small = Small;

var Checkboxes = function Checkboxes() {
  var demoId = "selector-demo-".concat(_randomstring["default"].generate(2));
  return /*#__PURE__*/_react["default"].createElement(_index.Selector, {
    name: demoId,
    type: "checkbox",
    onChange: function onChange(v) {
      (0, _addonActions.action)('onChange')(Array.isArray(v) ? v.join(', ') : v);
    },
    label: "Choose one",
    stateful: true
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two"
  }));
};

exports.Checkboxes = Checkboxes;

var MixinsMarginOnlySpacing = function MixinsMarginOnlySpacing() {
  return /*#__PURE__*/_react["default"].createElement(_marginChecker.MarginChecker, {
    Component: _index.Selector,
    name: "margin demo",
    type: "checkbox",
    onChange: function onChange(v) {
      (0, _addonActions.action)('onChange')(Array.isArray(v) ? v.join(', ') : v);
    },
    label: "Choose one"
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two"
  }));
};

exports.MixinsMarginOnlySpacing = MixinsMarginOnlySpacing;

var MixinsStackee = function MixinsStackee() {
  return /*#__PURE__*/_react["default"].createElement(_stackeeChecker.StackeeChecker, {
    Component: _index.Selector,
    name: "stackee demo",
    type: "checkbox",
    onChange: function onChange(v) {
      (0, _addonActions.action)('onChange')(Array.isArray(v) ? v.join(', ') : v);
    },
    label: "Choose one"
  }, /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-one",
    label: "First choice",
    value: "option-one"
  }), /*#__PURE__*/_react["default"].createElement(_selectorItem.SelectorItem, {
    id: "option-two",
    label: "Second choice",
    value: "option-two"
  }));
};

exports.MixinsStackee = MixinsStackee;