import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { useField, useMutationState, useEnvironment } from "@contember/binding";
import { FieldContainer } from "@contember/ui";
import { memo, useMemo } from "react";
import { useLabelMiddleware } from "../../environment/LabelMiddleware.js";
import { useAccessorErrors } from "../../errors/useAccessorErrors.js";
const SimpleRelativeSingleFieldProxy = memo(
  ({
    render,
    // Used by useField():
    defaultValue,
    isNonbearing,
    onBeforeUpdate,
    onInitialize,
    onUpdate,
    // Used only by FieldContainer:
    description,
    direction,
    gap,
    label,
    labelDescription,
    labelPosition,
    useLabelElement,
    width,
    // Used only by render():
    className,
    style,
    // Used by both render() and FieldContainer:
    errors,
    field: fieldName,
    required,
    size,
    // Used byt this proxy:
    containerClassName,
    containerStyle,
    suppressErrors,
    // Rest should be empty:
    ...rest
  }) => {
    const labelMiddleware = useLabelMiddleware();
    const normalizedLabel = useMemo(() => labelMiddleware(label), [labelMiddleware, label]);
    const useFieldProps = { defaultValue, field: fieldName, isNonbearing, onBeforeUpdate, onInitialize, onUpdate };
    const field = useField(useFieldProps);
    const fieldErrors = useAccessorErrors(field);
    const combinedErrors = !suppressErrors ? combineErrorMessages(errors, fieldErrors) : void 0;
    const fieldContainerProps = {
      description,
      direction,
      errors: combinedErrors,
      gap,
      label: normalizedLabel,
      labelDescription,
      labelPosition,
      required,
      size,
      useLabelElement,
      width,
      className: containerClassName,
      style: containerStyle
    };
    const renderProps = { field: fieldName, className, style, required, size, errors, ...rest };
    const isMutating = useMutationState();
    const environment = useEnvironment();
    const fieldMetadata = useMemo(
      () => ({
        field,
        environment,
        isMutating
      }),
      [environment, field, isMutating]
    );
    const rendered = render(fieldMetadata, renderProps);
    return /* @__PURE__ */ jsxDEV(Fragment, { children: rendered && /* @__PURE__ */ jsxDEV(FieldContainer, { ...fieldContainerProps, children: rendered }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/auxiliary/SimpleRelativeSingleField/SimpleRelativeFieldProxy.tsx",
      lineNumber: 114,
      columnNumber: 6
    }, globalThis) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/auxiliary/SimpleRelativeSingleField/SimpleRelativeFieldProxy.tsx",
      lineNumber: 112,
      columnNumber: 4
    }, globalThis);
  }
);
SimpleRelativeSingleFieldProxy.displayName = "SimpleRelativeSingleFieldProxy";
function combineErrorMessages(errors, fieldErrors) {
  if (!errors && !fieldErrors) {
    return void 0;
  } else {
    return [
      ...errors ?? [],
      ...fieldErrors ?? []
    ];
  }
}
export {
  SimpleRelativeSingleFieldProxy
};
//# sourceMappingURL=SimpleRelativeFieldProxy.js.map
