"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");

var _Tooltip = _interopRequireDefault(require("../Tooltip"));

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

/**
 * `Checkbox` component is used for turning an option on or off and selecting or deselecting an item.
 * @since 0.0.55
 */
const Checkbox = ({
  baseClassName = "".concat(_constants.CLS_PREFIX, "checkbox"),
  className,
  children,
  onChange,
  tooltip,
  checked,
  defaultChecked,
  disabled = false,
  name,
  indeterminate = false,
  inputProps,
  rightAddon,
  ...props
}) => {
  const handleChange = event => {
    if (!disabled && onChange) {
      onChange(event.target.checked);
    }
  };

  let result = /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, {
      ["".concat(baseClassName, "--disabled")]: disabled,
      ["".concat(baseClassName, "--indeterminate")]: indeterminate
    }, className)
  }, props), /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("label", {
    className: "".concat(baseClassName, "__label")
  }, /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({
    className: "".concat(baseClassName, "__input"),
    type: "checkbox",
    onChange: handleChange,
    checked: !indeterminate && checked,
    defaultChecked: defaultChecked,
    disabled: disabled,
    name: name
  }, inputProps)), /*#__PURE__*/_react.default.createElement("span", {
    className: "".concat(baseClassName, "__indicator")
  }), children ? /*#__PURE__*/_react.default.createElement("span", {
    className: "".concat(baseClassName, "__text")
  }, children) : null), rightAddon ? rightAddon : null));

  if (tooltip) {
    result = /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
      title: tooltip
    }, result);
  }

  return result;
};

var _default = Checkbox;
exports.default = _default;