"use strict";
const { mergeWith, isArray } = require("lodash");
const webpackConfig = require("./webpack.js");
const viteConfig = require("./vite.js");
const customizer = (objValue, srcValue) => {
  if (isArray(objValue)) {
    return objValue.concat(srcValue);
  }
};
const baseConfig = {
  addons: [
    {
      name: "@storybook/addon-docs",
      options: {
        sourceLoaderOptions: {
          injectStoryParameters: false
        }
      }
    },
    { name: "@storybook/addon-essentials", options: { docs: false } },
    "@storybook/addon-storysource",
    "@storybook/addon-links",
    "@storybook/addon-events",
    "@storybook/addon-interactions",
    "@storybook/addon-a11y"
  ],
  framework: "@storybook/react",
  features: {
    fastRefresh: true,
    storyStoreV7: true
    // babelModeV7: true,
  },
  reactOptions: {
    fastRefresh: true,
    strictMode: true,
    // react v17. remove this after upgrading storybook to v7
    legacyRootApi: true
  },
  typescript: {
    check: false,
    checkOptions: {},
    // reactDocgen: 'react-docgen-typescript', // ToDo: remove this once this plugin supports TS v5
    reactDocgen: false,
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      propFilter: (prop) => prop.parent ? !/node_modules/.test(prop.parent.fileName) : true,
      compilerOptions: {
        allowSyntheticDefaultImports: false,
        esModuleInterop: false
      }
    }
  }
};
module.exports = (viteBuilder = false) => {
  const config = viteBuilder ? viteConfig : webpackConfig;
  console.log("using", viteBuilder ? "vite" : "webpack", "builder config");
  return mergeWith(baseConfig, config, customizer);
};
