"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _constants = require("../../constants");

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
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 = `${_constants.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.default.createElement("label", (0, _extends2.default)({
    htmlFor: id,
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--disabled`]: disabled
    }, className)
  }, props), /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({
    className: `${baseClassName}__input`,
    type: "radio",
    name: name,
    id: id,
    onChange: handleChange,
    checked: checked,
    defaultChecked: defaultChecked,
    disabled: disabled
  }, inputProps)), /*#__PURE__*/_react.default.createElement("span", {
    className: `${baseClassName}__indicator`
  }), children ? /*#__PURE__*/_react.default.createElement("span", {
    className: `${baseClassName}__text`
  }, children) : null);
};

var _default = Radio;
exports.default = _default;