"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

require("core-js/modules/es.symbol");

require("core-js/modules/es.symbol.description");

require("core-js/modules/es.array.concat");

require("core-js/modules/es.array.filter");

require("core-js/modules/es.array.for-each");

require("core-js/modules/es.array.index-of");

require("core-js/modules/es.array.map");

require("core-js/modules/es.function.name");

require("core-js/modules/es.object.get-own-property-descriptor");

require("core-js/modules/es.object.get-own-property-descriptors");

require("core-js/modules/es.object.keys");

require("core-js/modules/es.regexp.exec");

require("core-js/modules/es.string.split");

require("core-js/modules/web.dom-collections.for-each");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createStories = exports.createSizeItems = exports.createUiItems = exports.createKnobs = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _merge = _interopRequireDefault(require("lodash/merge"));

var _react2 = require("@storybook/react");

var _reactRedux = require("react-redux");

var _redux = require("redux");

var _addonKnobs = require("@storybook/addon-knobs");

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

var _api = require("../../../../../../mono-pfm/packages/pfm-transactions/api.js");

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(source, true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var store = (0, _redux.createStore)(function () {});

var createKnobs = function createKnobs(props) {
  var knobs = {};
  Object.keys(props).forEach(function (key) {
    if (typeof props[key] !== 'function') {
      knobs[key] = typeof props[key] === 'boolean' ? (0, _addonKnobs.boolean)(key, false) : typeof props[key] === 'number' ? (0, _addonKnobs.number)(key, 0) : (0, _addonKnobs.text)(key, '');
    }
  });
  return knobs;
};

exports.createKnobs = createKnobs;

var createUiItems = function createUiItems(props) {
  var items = [{
    name: 'Default',
    props: (0, _merge.default)({}, props)
  }, {
    name: 'Primary',
    props: (0, _merge.default)({
      primary: true
    }, props)
  }, {
    name: 'Secondary',
    props: (0, _merge.default)({
      secondary: true
    }, props)
  }, {
    name: 'Success',
    props: (0, _merge.default)({
      success: true
    }, props)
  }, {
    name: 'Warning',
    props: (0, _merge.default)({
      warning: true
    }, props)
  }, {
    name: 'Danger',
    props: (0, _merge.default)({
      danger: true
    }, props)
  }, {
    name: 'Disabled',
    props: (0, _merge.default)({
      disabled: true
    }, props)
  }];
  return items;
};

exports.createUiItems = createUiItems;

var createSizeItems = function createSizeItems(props) {
  var items = [{
    name: 'Smallest (xxs)',
    props: (0, _merge.default)({
      xxs: true
    }, props)
  }, {
    name: 'Smaller (xs)',
    props: (0, _merge.default)({
      xs: true
    }, props)
  }, {
    name: 'Small (sm)',
    props: (0, _merge.default)({
      sm: true
    }, props)
  }, {
    name: 'Big (lg)',
    props: (0, _merge.default)({
      lg: true
    }, props)
  }, {
    name: 'Bigger (xl)',
    props: (0, _merge.default)({
      xl: true
    }, props)
  }, {
    name: 'Biggest (xxl)',
    props: (0, _merge.default)({
      xxl: true
    }, props)
  }];
  return items;
};

exports.createSizeItems = createSizeItems;

var createStories = function createStories(storyData, elem, storyName) {
  var generateUiItems = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  var generateSizeItems = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  var stories = (0, _react2.storiesOf)(storyName, module);
  var storyHeader = storyName.indexOf('.') > -1 ? storyName.split('.')[1] : storyName;
  stories.addDecorator(function (getStory) {
    return _react.default.createElement(_reactRedux.Provider, {
      store: store
    }, getStory());
  });
  storyData.stories.map(function (story) {
    story.chapters.map(function (chapter) {
      chapter.items = [];

      if (generateUiItems) {
        chapter.items = chapter.items.concat(createUiItems(chapter.props));
      }

      if (generateSizeItems) {
        chapter.items = chapter.items.concat(createSizeItems(chapter.props));
      }

      if (chapter.props) {
        chapter.description = 'Using props: ' + JSON.stringify(chapter.props);
      }
    });
  }); //Add story data to storybook

  storyData.stories.map(function (story) {
    story.chapters.map(function (chapter) {
      stories.add(chapter.name, function () {
        return _react.default.createElement(_index.Story, {
          header: storyHeader,
          key: storyName
        }, _react.default.createElement(_index.Chapter, {
          key: chapter.name,
          header: chapter.name,
          description: chapter.description,
          dark: chapter.dark
        }, chapter.items && chapter.items.length > 0 ? chapter.items.map(function (item, i) {
          return _react.default.createElement(_index.Item, {
            header: item.name,
            key: 'storyItem-' + i
          }, _react.default.createElement(elem, _objectSpread({}, item.props)));
        }) : _react.default.createElement(elem, _objectSpread({}, chapter.props))));
      }, {
        notes: chapter.notes || ''
      });
    });
  });

  if (elem && elem.defaultProps) {
    //Add playground story to storybook
    stories.add('Playground', function () {
      return _react.default.createElement(_index.Story, {
        header: "Playground"
      }, _react.default.createElement(_index.Chapter, {
        description: "Feel free to mess around with the 'knobs' to see how the component responds"
      }, _react.default.createElement(elem, _objectSpread({}, createKnobs(elem.defaultProps), {}, createKnobs({
        round: false,
        square: false,
        fill: false,
        solid: false
      }), {
        children: (0, _addonKnobs.text)('content', 'Text')
      }))));
    });
  }
};

exports.createStories = createStories;