import { Component } from "@contember/binding";
import { FieldContainer, Radio } from "@contember/ui";
import { memo, useMemo } from "react";
import { useLabelMiddleware } from "../environment/LabelMiddleware.js";
import { jsxDEV } from "react/jsx-dev-runtime";
import { ChoiceField } from "./ChoiceField/ChoiceField.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/fields/RadioField.tsx";
const RadioField = Component((props) => {
  return /* @__PURE__ */ jsxDEV(ChoiceField, {
    ...props,
    renderedOptionsLimit: 0,
    children: (choiceProps) => /* @__PURE__ */ jsxDEV(RadioFieldInner, {
      ...props,
      ...choiceProps
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 25,
      columnNumber: 5
    }, void 0)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 23,
    columnNumber: 3
  }, void 0);
}, "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__ */ jsxDEV(FieldContainer, {
    ...props,
    errors: props.errors,
    label: labelMiddleware(props.label),
    useLabelElement: false,
    children: /* @__PURE__ */ jsxDEV(Radio, {
      onChange: (it) => props.onSelect(optionsByKey.get(it)),
      options,
      size: props.size,
      orientation: props.orientation,
      value: props.currentValue?.key
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 63,
      columnNumber: 4
    }, void 0)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 57,
    columnNumber: 3
  }, void 0);
});
export {
  RadioField,
  RadioFieldInner
};
//# sourceMappingURL=RadioField.js.map
