text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.ConfirmStory = ConfirmStory;
  
  var _range2 = _interopRequireDefault(require("lodash/range"));
  
  var _chance = _interopRequireDefault(require("chance"));
  
  var _actions = require("part:@sanity/storybook/addons/actions");
  
  var _knobs = require("part:@sanity/storybook/addons/knobs");
  
  var _confirm = _interopRequireDefault(require("part:@sanity/components/dialogs/confirm"));
  
  var _portal = require("part:@sanity/components/portal");
  
  var _sanity = _interopRequireDefault(require("part:@sanity/storybook/addons/sanity"));
  
  var _react = _interopRequireWildcard(require("react"));
  
  var _excluded = ["children"];
  
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  
  var chance = new _chance.default();
  var dialogTestContent = {
    minimal: 'minimal',
    paragraph: 'paragraph',
    longtext: 'longtext',
    example: 'example with dialogcontent'
  };
  var paragraph = chance.paragraph();
  var paragraphs = (0, _range2.default)(0, 20).map(i => /*#__PURE__*/_react.default.createElement("p", {
    key: i
  }, chance.paragraph()));
  
  function renderContent(type) {
    switch (type) {
      case 'paragraph':
        return /*#__PURE__*/_react.default.createElement("p", null, paragraph);
  
      case 'longtext':
        return /*#__PURE__*/_react.default.createElement("div", null, paragraphs);
  
      case 'example':
        return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h1", null, "With dialog content"), /*#__PURE__*/_react.default.createElement("p", null, paragraph));
  
      default:
        return 'Minimal';
    }
  }
  
  function ConfirmStory() {
    var contentTest = (0, _knobs.select)('Content', dialogTestContent, 'minimal');
    return /*#__PURE__*/_react.default.createElement(_sanity.default, {
      part: "part:@sanity/components/dialogs/confirm",
      propTables: [_confirm.default]
    }, /*#__PURE__*/_react.default.createElement(DialogExample, {
      color: (0, _knobs.select)('color', ['default', 'danger', 'success', 'info', 'warning'], undefined, 'props'),
      confirmColor: (0, _knobs.select)('confirmColor', [undefined, 'danger', 'success'], undefined, 'props'),
      cancelColor: (0, _knobs.select)('cancelColor', [undefined, 'danger', 'success'], undefined, 'props'),
      onConfirm: (0, _actions.action)('onConfirm'),
      onCancel: (0, _actions.action)('onCancel'),
      confirmButtonText: (0, _knobs.text)('confirmButtonText', 'Yes, delete', 'props'),
      cancelButtonText: (0, _knobs.text)('cancelButtonText', undefined, 'props'),
      title: (0, _knobs.text)('title', 'Confirm', 'props'),
      size: "medium",
      padding: "medium"
    }, contentTest && renderContent(contentTest)));
  }
  
  function DialogExample(props) {
    var children = props.children,
        restProps = _objectWithoutProperties(props, _excluded);
  
    var portalRef = (0, _react.useRef)(document.createElement('div'));
    (0, _react.useEffect)(() => {
      portalRef.current.setAttribute('data-portal', '');
      document.body.appendChild(portalRef.current);
      return () => {
        document.body.removeChild(portalRef.current);
      };
    }, []);
    return /*#__PURE__*/_react.default.createElement(_portal.PortalProvider, {
      element: portalRef.current
    }, /*#__PURE__*/_react.default.createElement(_confirm.default, restProps, children));
  }