"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.MixinsStacked = exports.RestoresFocusTo = exports.HeaderText = exports.FocusedContent = exports.HiddenHeader = exports.Persistent = exports.Dissmissible = exports.Hidden = exports.XLarge = exports.LongBody = exports.Small = exports.Medium = exports.Default = exports["default"] = void 0;

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

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

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

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

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

var _tertiaryButton = require("../../actions/tertiary-button");

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

var _useModal4 = require("./use-modal");

var _stackedChecker = require("../../../mixins/stacking/story-support/stacked-checker");

var _modal = _interopRequireDefault(require("./modal.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.Modal,
  title: 'Modal',
  parameters: {
    docs: {
      page: _modal["default"]
    }
  }
};
exports["default"] = _default;
var BoxWithBorder = (0, _styledComponents["default"])(_primitives.Box).withConfig({
  displayName: "BoxWithBorder",
  componentId: "sc-6lf7ee-0"
})(["border-right:1px solid lightgrey;"]);

var DismissibleModal = function DismissibleModal() {
  var _useModal = (0, _useModal4.useModal)(),
      showModal = _useModal.showModal,
      onModalClose = _useModal.onModalClose,
      onModalToggle = _useModal.onModalToggle;

  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "row"
  }, /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    spacing: "mh4",
    onClick: onModalToggle
  }, "Open Modal"), /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    spacing: "mh4",
    onClick: function onClick() {
      return (0, _addonActions.action)('onButtonClick')('Blocked Button Clicked');
    }
  }, "Should Be Blocked When Modal Is Open"), /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: showModal,
    onClose: onModalClose
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something amazing I guess")));
};

var PersistentModal = function PersistentModal() {
  var _useModal2 = (0, _useModal4.useModal)(),
      showModal = _useModal2.showModal,
      onModalClose = _useModal2.onModalClose,
      onModalToggle = _useModal2.onModalToggle;

  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "row"
  }, /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    spacing: "mh4",
    onClick: onModalToggle
  }, "Open Modal"), /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    spacing: "mh4",
    onClick: function onClick() {
      return (0, _addonActions.action)('onButtonClick')('Blocked Button Clicked');
    }
  }, "Should Be Blocked When Modal Is Open"), /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: showModal,
    persistent: true,
    onClose: onModalClose
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "column",
    align: "center"
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something amazing I guess"), /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    spacing: "mt3",
    onClick: onModalClose
  }, "Close"))));
};

var Default = function Default() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose')
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something amazing I guess"));
};

exports.Default = Default;

var Medium = function Medium() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose'),
    size: "md"
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something medium amazing I guess"));
};

exports.Medium = Medium;

var Small = function Small() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose'),
    size: "sm"
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something small amazing I guess"));
};

exports.Small = Small;

var LongBody = function LongBody() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose')
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, null, /*#__PURE__*/_react["default"].createElement(_typography.Head2, null, "Are you a domestic politically exposed person, a foreign politically exposed person or a head of an international organization?"), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    bold: true
  }, "Domestic politically exposed person:"), /*#__PURE__*/_react["default"].createElement(_typography.Text, null, "A domestic PEP is a person (or the family member of a person) who holds \u2014 or has held within the last 5 years \u2014 an office or position in or on behalf of the Canadian federal government, a Canadian provincial government, or a Canadian municipal government: Governor General, lieutenant governor or head of government; member of the Senate or House of Commons or member of a legislature; deputy minister or equivalent rank; ambassador, or attach\xE9 or counsellor of an ambassador; military officer with a rank of general or above; president of a corporation that is wholly owned directly by Her Majesty in right of Canada or a province; head of a government agency; judge of an appellate court in a province, the Federal Court of Appeal or the Supreme Court of Canada; leader or president of a political party represented in a legislature; or mayor."), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    bold: true
  }, "Foreign politically exposed person:"), /*#__PURE__*/_react["default"].createElement(_typography.Text, null, "A foreign PEP is a person (or a family member or close associate of a person) who holds or has held one of the following offices or positions in or on behalf of a foreign state: head of state or head of government; member of the executive council of government or member of a legislature; deputy minister or equivalent rank; ambassador, or attach\xE9 or counsellor of an ambassador; military officer with a rank of general or above; president of a state-owned company or a state-owned bank; head of a government agency; judge of a supreme court, constitutional court or other court of last resort; or leader or president of a political party represented in a legislature. These persons are foreign PEPs regardless of citizenship, residence status or birth place."), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    bold: true
  }, "Head of an international organization:"), /*#__PURE__*/_react["default"].createElement(_typography.Text, null, "The head of an international organization is a person who is either: the head of an international organization established by the governments of states; or the head of an institution established by an international organization.")));
};

exports.LongBody = LongBody;

var XLarge = function XLarge() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose'),
    size: "xl",
    spacing: ['ph4', 'pb4']
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Large modal"));
};

exports.XLarge = XLarge;

var Hidden = function Hidden() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: false,
    onClose: (0, _addonActions.action)('onClose')
  }, /*#__PURE__*/_react["default"].createElement("div", null, "Something amazing I guess"));
};

exports.Hidden = Hidden;

var Dissmissible = function Dissmissible() {
  return /*#__PURE__*/_react["default"].createElement(DismissibleModal, null);
};

exports.Dissmissible = Dissmissible;

var Persistent = function Persistent() {
  return /*#__PURE__*/_react["default"].createElement(PersistentModal, null);
};

exports.Persistent = Persistent;

var HiddenHeader = function HiddenHeader() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose'),
    size: "xl",
    hideHeader: true,
    spacing: "ph2"
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: "row"
  }, /*#__PURE__*/_react["default"].createElement(BoxWithBorder, {
    spacing: "p6"
  }, "We want a full height border between this section..."), /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    spacing: "p6"
  }, "...and this section")));
};

exports.HiddenHeader = HiddenHeader;

var FocusedContent = function FocusedContent() {
  var _useState = (0, _react.useState)(''),
      _useState2 = _slicedToArray(_useState, 2),
      focusedText = _useState2[0],
      setFocusedText = _useState2[1];

  var onFocusTextChange = (0, _react.useCallback)(function (text) {
    (0, _addonActions.action)('onChange')(text);
    setFocusedText(text);
  }, [setFocusedText]);
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    onClose: (0, _addonActions.action)('onClose')
  }, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    label: "Focus me",
    name: "focus-me",
    placeholder: "The modal has disableAutoFocus = true",
    onChange: onFocusTextChange,
    focusOnMount: true,
    value: focusedText
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    label: "test-2",
    name: "test-2",
    onChange: (0, _addonActions.action)('onChange')
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    label: "test-3",
    name: "test-3",
    onChange: (0, _addonActions.action)('onChange')
  }));
};

exports.FocusedContent = FocusedContent;

var HeaderText = function HeaderText() {
  return /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: true,
    headerText: "Transfer a chequing or savings account",
    onClose: (0, _addonActions.action)('onClose')
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    spacing: "mv2"
  }, /*#__PURE__*/_react["default"].createElement(_typography.Head2, {
    align: "center"
  }, "Make a deposit instead")), /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    align: "center"
  }, "Savings and chequing accounts can't be transferred to Wealtsimple. But you can move the funds to your account faster by linking a bank account."));
};

exports.HeaderText = HeaderText;

var RestoresFocusTo = function RestoresFocusTo() {
  var _useModal3 = (0, _useModal4.useModal)(),
      showModal = _useModal3.showModal,
      onModalClose = _useModal3.onModalClose,
      onModalToggle = _useModal3.onModalToggle,
      refToRestoreFocus = _useModal3.refToRestoreFocus;

  var setRefToRestoreFocus = (0, _react.useCallback)(function (ref) {
    refToRestoreFocus.current = ref;
  }, [refToRestoreFocus]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_tertiaryButton.TertiaryButton, {
    onClick: onModalToggle
  }, "Click me to open modal"), /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    spacing: "pt2"
  }, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    onRef: setRefToRestoreFocus,
    label: "I will be focused after close",
    onChange: (0, _addonActions.action)('onChange')
  })), /*#__PURE__*/_react["default"].createElement(_index.Modal, {
    show: showModal,
    onClose: onModalClose,
    refToRestoreFocus: refToRestoreFocus
  }, /*#__PURE__*/_react["default"].createElement(_typography.Text, null, "Its worth mentioning you should almost always restore focus to the button you clicked on. We are focusing to a different button to show the setRefToRestoreFocus")));
};

exports.RestoresFocusTo = RestoresFocusTo;

var MixinsStacked = function MixinsStacked() {
  return /*#__PURE__*/_react["default"].createElement(_stackedChecker.StackedChecker, {
    Component: _index.Modal,
    show: true
  });
};

exports.MixinsStacked = MixinsStacked;