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

import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Tooltip from '../Tooltip';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
 * `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 = `${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__*/_jsxs("div", {
    className: classNames(baseClassName, {
      [`${baseClassName}--disabled`]: disabled,
      [`${baseClassName}--indeterminate`]: indeterminate
    }, className),
    ...props,
    children: [/*#__PURE__*/_jsxs("label", {
      className: `${baseClassName}__label`,
      children: [/*#__PURE__*/_jsx("input", {
        className: `${baseClassName}__input`,
        type: "checkbox",
        onChange: handleChange,
        checked: !indeterminate && checked,
        defaultChecked: defaultChecked,
        disabled: disabled,
        name: name,
        ...inputProps
      }), /*#__PURE__*/_jsx("span", {
        className: `${baseClassName}__indicator`
      }), children ? /*#__PURE__*/_jsx("span", {
        className: `${baseClassName}__text`,
        children: children
      }) : null]
    }), rightAddon ? rightAddon : null]
  });
  if (tooltip) {
    result = /*#__PURE__*/_jsx(Tooltip, {
      title: tooltip,
      children: result
    });
  }
  return result;
};
export default Checkbox;