import { joinPaths } from "../node_modules/.pnpm/@stryke_path@0.26.4/node_modules/@stryke/path/dist/join-paths.mjs";
import { getDocsOutputPath } from "../helpers/docs-helper.mjs";
import { stringifyType } from "@powerlines/deepkit/vendor/type";
import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
import { Show, code } from "@alloy-js/core";
import { Heading, Link } from "@alloy-js/markdown";
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
import { MarkdownFile } from "@powerlines/plugin-alloy/markdown/components/markdown-file";
import { MarkdownTable } from "@powerlines/plugin-alloy/markdown/components/markdown-table";

//#region src/components/docs.tsx
/**
* Generates the environment configuration markdown documentation for the Powerlines project.
*/
function EnvDocsFile(props) {
	const { levelOffset = 0, reflection, ...rest } = props;
	const context = usePowerlines();
	return createComponent(MarkdownFile, mergeProps({ get path() {
		return joinPaths(getDocsOutputPath(context), "env.md");
	} }, rest, { get children() {
		return [
			createComponent(Heading, {
				level: 1 + levelOffset,
				children: "Environment Configuration"
			}),
			code`Below is a list of environment variables used by the`,
			createComponent(Show, {
				get when() {
					return !!context.packageJson.name;
				},
				get children() {
					return createComponent(Link, {
						get href() {
							return `https://www.npmjs.com/package/${context.packageJson.name}`;
						},
						get title() {
							return context.packageJson.name;
						}
					});
				}
			}),
			code`package. These values can be updated in the \`.env\` file in the root of the project.`,
			createIntrinsic("hbr", {}),
			createComponent(Heading, {
				level: 2 + levelOffset,
				children: "Environment Variables"
			}),
			code`The below list of environment variables are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.`,
			createIntrinsic("hbr", {}),
			createComponent(MarkdownTable, { get data() {
				return reflection?.getProperties().filter((property) => property.getNameAsString() !== "__STORM_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
					return {
						name: reflectionProperty.getNameAsString().trim(),
						description: (reflectionProperty.getDescription() ?? "").trim(),
						type: stringifyType(reflectionProperty.getType()).trim().replaceAll(" | ", ", or "),
						defaultValue: reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : "",
						required: reflectionProperty.isValueRequired() ? "" : "✔"
					};
				}) ?? [];
			} })
		];
	} }));
}

//#endregion
export { EnvDocsFile };
//# sourceMappingURL=docs.mjs.map