import { memo, useMemo, createElement, Fragment } from "react";
import { useEnvironment, useField, useMutationState } from "@contember/binding";
import { FieldContainer } from "@contember/ui";
import { useLabelMiddleware } from "../../environment/LabelMiddleware.js";
import { useAccessorErrors } from "../../errors/useAccessorErrors.js";
const SimpleRelativeSingleFieldProxy = memo(({ render, label, labelDescription, labelPosition, description, ...props }) => {
  const environment = useEnvironment();
  const field = useField(props);
  const labelMiddleware = useLabelMiddleware();
  const normalizedLabel = useMemo(() => labelMiddleware(label), [labelMiddleware, label]);
  const isMutating = useMutationState();
  const fieldMetadata = useMemo(() => ({
    field,
    environment,
    isMutating
  }), [environment, field, isMutating]);
  const fieldErrors = useAccessorErrors(field);
  const rendered = render(fieldMetadata, props);
  return /* @__PURE__ */ createElement(Fragment, null, rendered && /* @__PURE__ */ createElement(FieldContainer, {
    label: normalizedLabel,
    size: props.size,
    labelDescription,
    labelPosition,
    description,
    errors: fieldErrors,
    required: props.required
  }, rendered));
});
SimpleRelativeSingleFieldProxy.displayName = "SimpleRelativeSingleFieldProxy";
export { SimpleRelativeSingleFieldProxy };
//# sourceMappingURL=SimpleRelativeFieldProxy.js.map
