import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React from 'react';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
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 = ({
  baseClassName = `${CLS_PREFIX}radio`,
  className,
  children,
  onChange,
  checked,
  defaultChecked,
  disabled = false,
  name,
  inputProps = {},
  ...props
}) => {
  const handleChange = event => {
    if (!disabled && onChange) {
      onChange(event.target.checked);
    }
  };

  const id = inputProps && inputProps.id || `radio-${radioId++}`;
  return /*#__PURE__*/React.createElement("label", _extends({
    htmlFor: id,
    className: classNames(baseClassName, {
      [`${baseClassName}--disabled`]: disabled
    }, className)
  }, props), /*#__PURE__*/React.createElement("input", _extends({
    className: `${baseClassName}__input`,
    type: "radio",
    name: name,
    id: id,
    onChange: handleChange,
    checked: checked,
    defaultChecked: defaultChecked,
    disabled: disabled
  }, inputProps)), /*#__PURE__*/React.createElement("span", {
    className: `${baseClassName}__indicator`
  }), children ? /*#__PURE__*/React.createElement("span", {
    className: `${baseClassName}__text`
  }, children) : null);
};

export default Radio;