import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import React from 'react';
import Switch from 'antd/es/switch';
import 'antd/es/switch/style';
import Menu from 'antd/es/menu';
import 'antd/es/menu/style';
import Dropdown from 'antd/es/dropdown';
import 'antd/es/dropdown/style';
import Icon from 'antd/es/icon';
import 'antd/es/icon/style';
import { VIEW_TYPES } from '../../../../../core/controlsBus/constants';
import './ViewSwitch.less';

var ViewSwitch =
/*#__PURE__*/
function (_React$Component) {
  _inherits(ViewSwitch, _React$Component);

  function ViewSwitch() {
    _classCallCheck(this, ViewSwitch);

    return _possibleConstructorReturn(this, _getPrototypeOf(ViewSwitch).apply(this, arguments));
  }

  _createClass(ViewSwitch, [{
    key: "renderMenu",
    value: function renderMenu() {
      var _this$props = this.props,
          name = _this$props.name,
          subMenuItems = _this$props.subMenuItems,
          checkedState = _this$props.checkedState,
          disabledState = _this$props.disabledState,
          toggleSwitch = _this$props.toggleSwitch,
          fireButtonAction = _this$props.fireButtonAction;
      var menu = React.createElement(Menu, null, subMenuItems.map(function (item) {
        var menuItem = null;

        if (item.type === VIEW_TYPES.BUTTON) {
          var itemName = React.createElement(React.Fragment, null, item.icon ? React.createElement(Icon, {
            type: item.icon
          }) : null, React.createElement("span", {
            title: item.title
          }, ' ' + item.name));
          menuItem = !disabledState[item.key] ? React.createElement("a", {
            title: item.title,
            onClick: function onClick() {
              return fireButtonAction(item.key);
            }
          }, itemName) : itemName;
        } else {
          var tickAndName = React.createElement(React.Fragment, null, checkedState[item.key] ? React.createElement(Icon, {
            type: 'check'
          }) : null, React.createElement("span", {
            title: item.title
          }, item.name));
          menuItem = !disabledState[item.key] ? React.createElement("a", {
            title: item.title,
            onClick: function onClick() {
              return toggleSwitch(item.key, !checkedState[item.key]);
            }
          }, tickAndName) : tickAndName;
        }

        return React.createElement(Menu.Item, {
          key: "".concat(name, "-").concat(item.key),
          disabled: disabledState[item.key]
        }, menuItem);
      }));
      return React.createElement(Dropdown, {
        overlay: menu,
        trigger: ['click']
      }, React.createElement("a", {
        href: "#",
        className: "viewSwitchName"
      }, name, React.createElement(Icon, {
        type: "down"
      })));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          name = _this$props2.name,
          itemKey = _this$props2.itemKey,
          subMenuItems = _this$props2.subMenuItems,
          checkedState = _this$props2.checkedState,
          toggleSwitch = _this$props2.toggleSwitch;
      return React.createElement("div", {
        className: "ViewSwitchItem"
      }, React.createElement("div", {
        className: "big-item"
      }, checkedState[itemKey] && subMenuItems.length ? this.renderMenu() : React.createElement("span", {
        className: "viewSwitchName"
      }, name), React.createElement(Switch, {
        size: "small",
        checked: checkedState[itemKey],
        onChange: function onChange(v) {
          return toggleSwitch(itemKey, v);
        }
      })));
    }
  }]);

  return ViewSwitch;
}(React.Component);

export default ViewSwitch;