"use strict";

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

/**
 * `SwitchesPanelItem` component is used for combining [Switch](#!/Switch) component with text title and description.
 * Used in [SwitchesPanel](#!/SwitchesPanel).
 * @since 0.3.0
 */
class SwitchesPanelItem extends _react.Component {
  constructor() {
    super(...arguments);
    (0, _defineProperty2.default)(this, "state", {
      checked: this.props.defaultChecked
    });
    (0, _defineProperty2.default)(this, "handleChange", checked => {
      this.setState({
        checked
      });
      this.props.onChange(checked);
    });
  }
  render() {
    const {
      onChange,
      defaultChecked,
      intent,
      title,
      description,
      fullDescription,
      baseClassName,
      className,
      switchProps,
      children,
      ...props
    } = this.props;
    const {
      checked
    } = this.state;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: (0, _classnames.default)(baseClassName, {
        [`${baseClassName}--${intent}`]: intent && checked
      }, className),
      ...props,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h5", {
        className: `${baseClassName}__title`,
        children: title
      }), description && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: `${baseClassName}__description`,
        children: description
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: `${baseClassName}__actions`,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Switch.default, {
          className: `${baseClassName}__switch`,
          intent: intent,
          onChange: this.handleChange,
          defaultChecked: defaultChecked,
          ...switchProps
        }), (fullDescription || children) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          className: `${baseClassName}__controls`,
          children: [children, fullDescription && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popover.default, {
            intent: "info",
            target: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Action.default, {
              icon: "question-mark-circle",
              outerProps: {
                className: `${baseClassName}__full-description-toggle`
              }
            }),
            placement: "bottom",
            children: fullDescription
          })]
        })]
      })]
    });
  }
}
(0, _defineProperty2.default)(SwitchesPanelItem, "defaultProps", {
  defaultChecked: false,
  intent: null,
  description: null,
  fullDescription: null,
  switchProps: {},
  children: null,
  className: null,
  baseClassName: `${_constants.CLS_PREFIX}switches-panel-item`
});
var _default = exports.default = SwitchesPanelItem;