import { UserConfigExport } from '@armit/config-loader';
import { PartialDeep } from 'type-fest';

export interface TSandPackEnvOptions {
	/**
	 * Test code dependencies
	 * - Used to configure the dependencies required by Sandpack to run the test code
	 * @example
	 * ```
	 * { '@dimjs/lang': '1.2.44' }
	 * ```
	 */
	dependencies: Record<string, string>;
	/**
	 * Address of sandpack bundler service
	 * @example `http://localhost:1234/`
	 */
	bundlerURL: string;
	/**
	 * Whether to run test code automatically
	 * @default true
	 */
	autorun?: boolean;
}
export interface TWebContainerEnvOptions {
	/**
	 * Test code dependencies
	 * - Used to configure the dependencies required by WebContainer to run the test code
	 * @example
	 * ```
	 * { '@dimjs/lang': '1.2.44' }
	 * ```
	 */
	dependencies: Record<string, string>;
	/**
	 * Run the current command automatically
	 * During the webcontainer initialization phase
	 *
	 * @example
	 * ```
	 * [ 'pnpm install', 'npm run test' ]
	 * ```
	 */
	autoRunCmd?: string[];
}
export interface TranspileModuleOption {
	/**
	 * The package name of the module
	 *
	 * @example
	 * `@dimjs/lang`
	 */
	packageName: string;
	/**
	 * The base url for the git
	 * Used to link the git repository address corresponding to the source code
	 *
	 * @example
	 * `https://gitlab.itcjf.com/flatjs-next/tool-kits/tree/master/`
	 */
	sourceBaseUrl: string;
	/**
	 * The base url for the npm package.
	 * Used to link the corresponding dependent repository address
	 *
	 * @default `https://www.npmjs.com/package/`
	 */
	npmBaseUrl?: string;
	/**
	 * Used to configure how to specify the test file to generate the corresponding test code for online preview
	 * - Generate react code for *.spec.ts file
	 */
	moduleCodeOptions?: IModuleCodeOption;
	/**
	 * The doc options
	 * - Used to generate the corresponding mdx from *.js | *.ts
	 * - This function is based on jsdoc for code parsing https://www.jsdoc.com.cn/
	 */
	moduleDocOptions?: IModuleDocOption;
	/**
	 * The sandpack bundler, The goal is to compile the code online so sandpack can load the final result in real time
	 * Currently only react code compilation is supported
	 * https://sandpack-bundler.codesandbox.io/
	 */
	sandPackBundler?: TSandPackEnvOptions;
	/**
	 * The environment required for webContainer to run
	 * Currently only js code compilation is supported
	 */
	webContainer?: TWebContainerEnvOptions;
}
export interface IModuleCodeOption {
	/**
	 * The current module needs to generate code the directory
	 * Relative to the root directory
	 *
	 * @example
	 * ['packages/lang/src','packages/lang/test']
	 *
	 * @default src
	 */
	sourceDirs: string[];
	/**
	 * Contains all files under the current rule
	 * Used to filter the range of files covered by the generated code
	 * Scope: transpile code files
	 *
	 * @default [/\.spec\.ts$/, /\.test\.ts$/]
	 */
	include?: RegExp[];
	/**
	 * Exclude files under the current rule
	 * Used to exclude the range of files covered by the generated code
	 * Scope: transpile code files
	 *
	 * @default []
	 */
	exclude?: RegExp[];
	/**
	 * Code Type of the conversion
	 * This configuration is valid for all mdx in the current module, if you want to customize the preview of mdx, please use the @codeMode comment
	 * - If the codeMode is react, the code will be converted to react test code
	 * - If the codeMode is node, the code will be converted to vitest code
	 *
	 * @default react
	 */
	codeMode?: TIModuleCodeMode;
}
export type TIModuleCodeMode = "react" | "node";
export interface IModuleDocOption {
	/**
	 * Markdown output
	 */
	output: string;
	/**
	 * The current module needs to generate the doc directory
	 * Relative to the root directory
	 *
	 * @example ['packages/lang/src','packages/lang/test']
	 *
	 * @default src
	 */
	sourceDirs: string[];
	/**
	 * Contains all files under the current rule
	 * Used to filter the range of files covered by the generated code
	 * Scope: transpile mdx files
	 *
	 * @default [/\.*\.ts$/]
	 */
	include?: RegExp[];
	/**
	 * Exclude files under the current rule
	 * Used to exclude the range of files covered by the generated code
	 * Scope: transpile mdx files
	 *
	 * @default []
	 */
	exclude?: RegExp[];
	/**
	 * Generate the index.mdx file under the corresponding category
	 * Can do the current classification of information integration
	 *
	 * @default false
	 */
	generateIndexMd?: boolean;
}
export interface FlatDocOptions {
	/**
	 * The project root directory
	 */
	projectCwd: string;
	/**
	 * Inject code at the top of the mdx file
	 *
	 * @default
	 * [
	 *  "import react, { useEffect, useState } from 'react'",
	 *  "import { Callout, Steps } from 'nextra/components'",
	 *  "import { MdxGenerationInfo, H1, H2, H3, H4, H5, MdxMemberInfo, MdxSandPack, MdxSimpleCallout } from '@flatjs/nextra/components'",
	 * ]
	 */
	injectMdxCode?: string[];
	/**
	 * Markdown file suffix
	 *
	 * @default .mdx
	 */
	mdFileSuffix?: string;
	/**
	 * Configure the modules to be compiled
	 */
	transpileModule: TranspileModuleOption[];
}
export type ConfigLoaderOptions = {
	configFile: string;
};
/**
 * @description doc build start
 * @param projectCwd the project root directory which will be build.
 * @param overrideOptions The override options.
 * @param configLoaderOptions The customized config loader options, normally will used by `Unitest`
 *
 * @returns {Promise<boolean>} build status
 */
export declare const startBuild: (projectCwd?: string, overrideOptions?: PartialDeep<FlatDocOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<boolean>;
export type DefineConfigFn = (userConfig: PartialDeep<FlatDocOptions>) => UserConfigExport<PartialDeep<FlatDocOptions>>;
export declare const defineConfig: DefineConfigFn;

export {};
