// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
let radioId = 0;

/**
 * `Radio` component is used for making a choice among a set of mutually exclusive, related options.
 * @since 3.2.0
 */
const Radio = _ref => {
  let {
    baseClassName = `${CLS_PREFIX}radio`,
    className,
    children,
    onChange,
    checked,
    defaultChecked,
    disabled = false,
    name,
    inputProps = {},
    ...props
  } = _ref;
  const handleChange = event => {
    if (!disabled && onChange) {
      onChange(event.target.checked);
    }
  };
  const id = inputProps && inputProps.id || `radio-${radioId++}`;
  return /*#__PURE__*/_jsxs("label", {
    htmlFor: id,
    className: classNames(baseClassName, {
      [`${baseClassName}--disabled`]: disabled
    }, className),
    ...props,
    children: [/*#__PURE__*/_jsx("input", {
      className: `${baseClassName}__input`,
      type: "radio",
      name: name,
      id: id,
      onChange: handleChange,
      checked: checked,
      defaultChecked: defaultChecked,
      disabled: disabled,
      ...inputProps
    }), /*#__PURE__*/_jsx("span", {
      className: `${baseClassName}__indicator`
    }), children ? /*#__PURE__*/_jsx("span", {
      className: `${baseClassName}__text`,
      children: children
    }) : null]
  });
};
export default Radio;