"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = parse;
exports.test = exports.story = exports.kind = void 0;
var _csf = require("@storybook/csf");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
async function parse(files) {
  result = {};
  await Promise.all(files.map(async file => (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(file)));
  return result;
}
let result = {};
let kindTitle = '';
let storyTitle = '';
let storyParams = null;
const setStoryParameters = params => {
  storyParams = params;
};
const getStoryId = (kindTitle, storyTitle) => {
  return (0, _csf.toId)(kindTitle, (0, _csf.storyNameFromExport)(storyTitle));
};
const kind = (title, kindFn) => {
  kindTitle = title;
  kindFn();
  kindTitle = '';
};
exports.kind = kind;
const story = (title, storyFn) => {
  var _result$storyId;
  storyTitle = title;
  storyParams = null;
  storyFn({
    setStoryParameters
  });
  const storyId = getStoryId(kindTitle, storyTitle);
  result[storyId] = Object.assign({}, storyParams, {
    tests: (_result$storyId = result[storyId]) === null || _result$storyId === void 0 ? void 0 : _result$storyId.tests
  });
  storyTitle = '';
  storyParams = null;
};
exports.story = story;
const test = (title, testFn) => {
  const storyId = getStoryId(kindTitle, storyTitle);
  if (!result[storyId]) {
    result[storyId] = {};
  }
  result[storyId].tests = Object.assign({}, result[storyId].tests, {
    [title]: testFn
  });
};
exports.test = test;