"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. 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 = _ref => {
  let {
    baseClassName = `${_constants.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__*/(0, _jsxRuntime.jsxs)("label", {
    htmlFor: id,
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--disabled`]: disabled
    }, className),
    ...props,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
      className: `${baseClassName}__input`,
      type: "radio",
      name: name,
      id: id,
      onChange: handleChange,
      checked: checked,
      defaultChecked: defaultChecked,
      disabled: disabled,
      ...inputProps
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: `${baseClassName}__indicator`
    }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: `${baseClassName}__text`,
      children: children
    }) : null]
  });
};
var _default = exports.default = Radio;