"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 _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. 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 = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}checkbox`,
    className,
    children,
    onChange,
    tooltip,
    checked,
    defaultChecked,
    disabled = false,
    name,
    indeterminate = false,
    inputProps,
    rightAddon,
    ...props
  } = _ref;
  const handleChange = event => {
    if (!disabled && onChange) {
      onChange(event.target.checked);
    }
  };
  let result = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--disabled`]: disabled,
      [`${baseClassName}--indeterminate`]: indeterminate
    }, className),
    ...props,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
      className: `${baseClassName}__label`,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
        className: `${baseClassName}__input`,
        type: "checkbox",
        onChange: handleChange,
        checked: !indeterminate && checked,
        defaultChecked: defaultChecked,
        disabled: disabled,
        name: name,
        ...inputProps
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        className: `${baseClassName}__indicator`
      }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        className: `${baseClassName}__text`,
        children: children
      }) : null]
    }), rightAddon ? rightAddon : null]
  });
  if (tooltip) {
    result = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
      title: tooltip,
      children: result
    });
  }
  return result;
};
var _default = exports.default = Checkbox;