"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _Checkbox = _interopRequireDefault(require("../Checkbox"));
var _FormField = _interopRequireDefault(require("../FormField"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `FormFieldCheckbox` component is used for turning an option on or off
 * and selecting or deselecting an item.
 * @since 0.0.58
 */
const FormFieldCheckbox = _ref => {
  let {
    className,
    label,
    autoFocus,
    required = false,
    checkedValue = true,
    uncheckedValue = false,
    baseClassName = `${_constants.CLS_PREFIX}form-field-checkbox`,
    ...props
  } = _ref;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormField.default, {
    className: (0, _classnames.default)(baseClassName, className),
    label: null,
    required: required,
    ...props,
    children: _ref2 => {
      let {
        getId,
        getName,
        getValue,
        setValue,
        getRequiredMark,
        getFullDescription,
        isDisabled
      } = _ref2;
      return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
          type: "hidden",
          name: getName(),
          value: uncheckedValue.toString()
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
          checked: getValue() === checkedValue,
          onChange: checked => setValue(checked ? checkedValue : uncheckedValue),
          inputProps: {
            id: getId(),
            name: getName(),
            value: checkedValue.toString(),
            autoFocus
          },
          disabled: isDisabled(),
          rightAddon: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
            children: [getFullDescription(), required ? getRequiredMark() : null]
          }),
          children: label
        })]
      });
    }
  });
};
var _default = exports.default = FormFieldCheckbox;