import { t as __ΩEnvPluginContext } from "./plugin-eBjQJP6x.mjs";
import { o as readEnvTypeReflection } from "./persistence-BsBxs9wt.mjs";
import { n as loadEnvFromContext } from "./load-Dr5ybfL7.mjs";
import { ReflectionClass, ReflectionKind } from "@powerlines/deepkit/vendor/type";
import { titleCase } from "@stryke/string-format/title-case";
import { computed, createResource } from "@alloy-js/core";

//#region src/helpers/create-reflection-resource.ts
const __ΩRecord = [
	"K",
	"T",
	"Record",
	"l'e#\"Rb!b\"Pde\"!N#!w#y"
];
function __assignType(fn, args) {
	fn.__type = args;
	return fn;
}
/**
* Creates a reflection resource for the environment configuration.
*
* @param context - The environment plugin context.
* @returns A resource that provides the reflection of the environment configuration.
*/
function createReflectionResource(context) {
	const defaultValue = computed(() => context && loadEnvFromContext(context, process.env));
	return createResource.Ω = [[
		() => __ΩRecord,
		() => ReflectionClass,
		"P&\"o!#7\""
	]], createResource(async () => {
		if (!context) return new ReflectionClass({
			kind: ReflectionKind.objectLiteral,
			description: `The initial environment configuration state for the Powerlines project.`,
			types: []
		});
		const result = await readEnvTypeReflection(context, "env");
		result.getProperties().forEach(__assignType((prop) => {
			prop.getAlias().filter(Boolean).forEach(__assignType((alias) => {
				result.addProperty({
					name: alias,
					optional: prop.isOptional() ? true : void 0,
					readonly: prop.isReadonly() ? true : void 0,
					description: prop.getDescription(),
					visibility: prop.getVisibility(),
					type: prop.getType(),
					default: prop.getDefaultValue(),
					tags: {
						hidden: prop.isHidden(),
						ignore: prop.isIgnored(),
						internal: prop.isInternal(),
						alias: prop.getAlias().filter(__assignType((a) => a !== alias, [
							"a",
							"",
							"P\"2!\"/\""
						])).concat(prop.name),
						title: prop.getTitle() || titleCase(prop.name),
						readonly: prop.isReadonly(),
						permission: prop.getPermission(),
						domain: prop.getDomain()
					}
				});
			}, [
				"alias",
				"",
				"P\"2!\"/\""
			]));
		}, [
			"prop",
			"",
			"P\"2!\"/\""
		]));
		result.getProperties().forEach(__assignType((prop) => {
			prop.setDefaultValue(defaultValue.value?.[prop.getNameAsString()] ?? prop.getAlias().reduce(__assignType((ret, alias) => ret ?? defaultValue.value?.[alias], [
				"ret",
				"alias",
				"",
				"P\"2!\"2\"\"/#"
			]), void 0) ?? prop.getDefaultValue());
		}, [
			"prop",
			"",
			"P\"2!\"/\""
		]));
		return result;
	});
}
createReflectionResource.__type = [
	() => __ΩEnvPluginContext,
	"context",
	"createReflectionResource",
	"Creates a reflection resource for the environment configuration.",
	"Pn!2\"8\"/#?$"
];

//#endregion
export { createReflectionResource as t };
//# sourceMappingURL=create-reflection-resource-B3friIs9.mjs.map