import _defineProperty from "@babel/runtime/helpers/defineProperty";
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import { Component } from 'react';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Switch from '../Switch';
import Action from '../Action';
import Popover from '../Popover';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
 * `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 Component {
  constructor() {
    super(...arguments);
    _defineProperty(this, "state", {
      checked: this.props.defaultChecked
    });
    _defineProperty(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__*/_jsxs("div", {
      className: classNames(baseClassName, {
        [`${baseClassName}--${intent}`]: intent && checked
      }, className),
      ...props,
      children: [/*#__PURE__*/_jsx("h5", {
        className: `${baseClassName}__title`,
        children: title
      }), description && /*#__PURE__*/_jsx("p", {
        className: `${baseClassName}__description`,
        children: description
      }), /*#__PURE__*/_jsxs("div", {
        className: `${baseClassName}__actions`,
        children: [/*#__PURE__*/_jsx(Switch, {
          className: `${baseClassName}__switch`,
          intent: intent,
          onChange: this.handleChange,
          defaultChecked: defaultChecked,
          ...switchProps
        }), (fullDescription || children) && /*#__PURE__*/_jsxs("div", {
          className: `${baseClassName}__controls`,
          children: [children, fullDescription && /*#__PURE__*/_jsx(Popover, {
            intent: "info",
            target: /*#__PURE__*/_jsx(Action, {
              icon: "question-mark-circle",
              outerProps: {
                className: `${baseClassName}__full-description-toggle`
              }
            }),
            placement: "bottom",
            children: fullDescription
          })]
        })]
      })]
    });
  }
}
_defineProperty(SwitchesPanelItem, "defaultProps", {
  defaultChecked: false,
  intent: null,
  description: null,
  fullDescription: null,
  switchProps: {},
  children: null,
  className: null,
  baseClassName: `${CLS_PREFIX}switches-panel-item`
});
export default SwitchesPanelItem;