import { useEnvironment, useField, useMutationState } from "@contember/binding";
import { FieldContainer } from "@contember/ui";
import { memo, useMemo } from "react";
import { useLabelMiddleware } from "../../environment/LabelMiddleware.js";
import { jsx, Fragment } from "react/jsx-runtime";
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__ */ jsx(Fragment, {
    children: rendered && /* @__PURE__ */ jsx(FieldContainer, {
      label: normalizedLabel,
      size: props.size,
      labelDescription,
      labelPosition,
      description,
      errors: fieldErrors,
      required: props.required,
      children: rendered
    })
  });
});
SimpleRelativeSingleFieldProxy.displayName = "SimpleRelativeSingleFieldProxy";
export {
  SimpleRelativeSingleFieldProxy
};
//# sourceMappingURL=SimpleRelativeFieldProxy.js.map
