import { createElement, memo, useMemo } from "react";
import { Component } from "@contember/binding";
import { FieldContainer, Radio } from "@contember/ui";
import { useLabelMiddleware } from "../environment/LabelMiddleware.js";
import { ChoiceField } from "./ChoiceField/ChoiceField.js";
const RadioField = Component((props) => {
  return /* @__PURE__ */ createElement(ChoiceField, {
    ...props,
    renderedOptionsLimit: 0
  }, (choiceProps) => /* @__PURE__ */ createElement(RadioFieldInner, {
    ...props,
    ...choiceProps
  }));
}, "RadioField");
const RadioFieldInner = memo((props) => {
  const labelMiddleware = useLabelMiddleware();
  const [options, optionsByKey] = useMemo(() => {
    const options2 = [];
    const optionsByKey2 = /* @__PURE__ */ new Map();
    for (const option of props.data) {
      const value = option.key.toString();
      options2.push({
        value,
        label: option.label,
        labelDescription: option.description
      });
      optionsByKey2.set(value, option);
    }
    return [options2, optionsByKey2];
  }, [props.data]);
  return /* @__PURE__ */ createElement(FieldContainer, {
    ...props,
    errors: props.errors,
    label: labelMiddleware(props.label),
    useLabelElement: false
  }, /* @__PURE__ */ createElement(Radio, {
    onChange: (it) => props.onSelect(optionsByKey.get(it)),
    options,
    size: props.size,
    orientation: props.orientation,
    value: props.currentValue?.key
  }));
});
export { RadioField, RadioFieldInner };
//# sourceMappingURL=RadioField.js.map
