/*
 * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Radio } from "@base-ui/react/radio";
import { RadioGroup } from "@base-ui/react/radio-group";
import React, { memo, useCallback, useId, useMemo } from "react";
import { typedReactMemo } from "../../shared/typedMemo.js";
import styles from "./RadioButtonsField.module.css.js";
export const RadioButtonsField = typedReactMemo(function ({
  id,
  value,
  onChange,
  options,
  orientation,
  disabled
}) {
  const selectedLabel = useMemo(() => value != null ? options.find(opt => opt.value === value)?.label : undefined, [options, value]);
  const handleValueChange = useCallback(nextLabel => {
    const match = options.find(opt => opt.label === nextLabel);
    onChange?.(match?.value ?? null);
  }, [options, onChange]);
  return /*#__PURE__*/React.createElement(RadioGroup, {
    id: id,
    className: styles.osdkRadioGroup,
    "data-orientation": orientation ?? "vertical",
    value: selectedLabel,
    onValueChange: handleValueChange,
    disabled: disabled
  }, options.map(option => /*#__PURE__*/React.createElement(RadioItem, {
    key: option.label,
    option: option,
    disabled: disabled
  })));
});
const RadioItem = /*#__PURE__*/memo(function ({
  option,
  disabled
}) {
  const labelId = useId();
  return /*#__PURE__*/React.createElement("label", {
    className: styles.osdkRadioItem
  }, /*#__PURE__*/React.createElement(Radio.Root, {
    value: option.label,
    className: styles.osdkRadioRoot,
    disabled: disabled,
    "aria-labelledby": labelId,
    tabIndex: disabled === true ? -1 : undefined
  }, /*#__PURE__*/React.createElement(Radio.Indicator, {
    className: styles.osdkRadioIndicator
  })), /*#__PURE__*/React.createElement("span", {
    id: labelId,
    className: styles.osdkRadioLabel
  }, option.label));
});
//# sourceMappingURL=RadioButtonsField.js.map