import widgets from "./widgets/index.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Typography } from "@material-ui/core";
import { mapKeys } from "lodash-es";
//#region src/UI/property/PropertyFields.jsx
/**
* Convert a simple key/value properties object to an initialValues object with the prefixes used by widget components
*/
function getFieldValuesForProperties(type, properties) {
	return mapKeys(properties, (value, key) => `${type}:${key}`);
}
/**
* Convert a values object with the prefixes used by widget components into a simple key/value properties object
*/
function getPropertiesForFieldValues(type, values) {
	const properties = {};
	for (const key in values) if (key.startsWith(type + ":")) properties[key.substr(type.length + 1)] = values[key];
	return properties;
}
/**
* Single dynamic widget for a component property
*/
const PropertyWidget = (props) => {
	const $ = c(8);
	const { propertyType, property, initialData, disabled } = props;
	const { type } = property;
	if (type in widgets) {
		const WidgetPropertyComponent = widgets[type];
		let t0;
		if ($[0] !== WidgetPropertyComponent || $[1] !== disabled || $[2] !== initialData || $[3] !== property || $[4] !== propertyType) {
			t0 = /* @__PURE__ */ React.createElement(WidgetPropertyComponent, {
				propertyType,
				property,
				initialData,
				disabled
			});
			$[0] = WidgetPropertyComponent;
			$[1] = disabled;
			$[2] = initialData;
			$[3] = property;
			$[4] = propertyType;
			$[5] = t0;
		} else t0 = $[5];
		return t0;
	}
	let t0;
	if ($[6] !== type) {
		t0 = /* @__PURE__ */ React.createElement(Typography, { color: "error" }, "Unknown property type ", type);
		$[6] = type;
		$[7] = t0;
	} else t0 = $[7];
	return t0;
};
/**
* Shared component for outputting dynamic fields from properties table
*/
const PropertyField = (props) => {
	const $ = c(5);
	const { propertyType, property, initialData, disabled } = props;
	let t0;
	if ($[0] !== disabled || $[1] !== initialData || $[2] !== property || $[3] !== propertyType) {
		t0 = /* @__PURE__ */ React.createElement(PropertyWidget, {
			propertyType,
			property,
			initialData,
			disabled
		});
		$[0] = disabled;
		$[1] = initialData;
		$[2] = property;
		$[3] = propertyType;
		$[4] = t0;
	} else t0 = $[4];
	return t0;
};
/**
* Shared component for outputting dynamic fields from properties table
*/
const PropertyFields = (props) => {
	const { propertyType, propertyTable, initialData } = props;
	return propertyTable.map((p) => /* @__PURE__ */ React.createElement(PropertyWidget, {
		key: p.key,
		propertyType,
		property: p,
		initialData
	}));
};
//#endregion
export { PropertyField, PropertyFields, getFieldValuesForProperties, getPropertiesForFieldValues };

//# sourceMappingURL=PropertyFields.mjs.map