import { isObject } from "@scalar/helpers/object/is-object";
import { resolve } from "@scalar/workspace-store/resolve";
import { objectEntries } from "@scalar/helpers/object/object-entries";
import { isObjectSchema } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
//#region src/v2/blocks/request-block/helpers/get-form-body-rows.ts
var stringifyValue = (value) => {
	if (value instanceof File) return value.name;
	if (typeof value === "object" && value !== null) return JSON.stringify(value);
	return String(value);
};
/** Build the table rows for the form data, optionally enriched with schema (e.g. enum) per property */
var getFormBodyRows = (example, contentType, formBodySchema) => {
	if (!example?.value || contentType !== "multipart/form-data" && contentType !== "application/x-www-form-urlencoded") return [];
	const schemaWithProperties = formBodySchema && isObjectSchema(formBodySchema) ? formBodySchema : void 0;
	const requiredSet = schemaWithProperties ? new Set(schemaWithProperties.required ?? []) : void 0;
	const mapRow = ({ name, value, isDisabled = false }) => {
		const row = {
			name,
			value,
			isDisabled
		};
		if (!schemaWithProperties || !name) return row;
		const propSchema = resolve.schema(schemaWithProperties.properties?.[name]);
		row.schema = propSchema;
		row.description = propSchema?.description;
		row.isRequired = requiredSet?.has(name);
		row.isDisabled = isDisabled;
		return row;
	};
	if (Array.isArray(example.value)) return example.value.map((exampleValue) => {
		if (isObject(exampleValue)) return mapRow({
			name: String(exampleValue.name),
			value: exampleValue.value instanceof File ? exampleValue.value : String(exampleValue.value),
			isDisabled: Boolean(exampleValue.isDisabled)
		});
		return {
			name: "",
			value: exampleValue,
			isDisabled: false
		};
	});
	if (typeof example.value === "object" && example.value) return objectEntries(example.value).map(([key, value]) => mapRow({
		name: String(key),
		value: stringifyValue(value)
	}));
	return [];
};
//#endregion
export { getFormBodyRows };

//# sourceMappingURL=get-form-body-rows.js.map