import { toId, storyNameFromExport } from '@storybook/csf';
export default async function parse(files) {
  result = {};
  await Promise.all(files.map(async file => import(file)));
  return result;
}
let result = {};
let kindTitle = '';
let storyTitle = '';
let storyParams = null;
const setStoryParameters = params => {
  storyParams = params;
};
const getStoryId = (kindTitle, storyTitle) => {
  return toId(kindTitle, storyNameFromExport(storyTitle));
};
export const kind = (title, kindFn) => {
  kindTitle = title;
  kindFn();
  kindTitle = '';
};
export 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;
};
export const test = (title, testFn) => {
  const storyId = getStoryId(kindTitle, storyTitle);
  if (!result[storyId]) {
    result[storyId] = {};
  }
  result[storyId].tests = Object.assign({}, result[storyId].tests, {
    [title]: testFn
  });
};