import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import { connect } from "../../../redux";
import { IconButton } from '@webiny/ui/Button';
import { ReactComponent as ThemeIcon } from "@svgr/webpack!../../../assets/icons/global-theme-icon.svg";
import ModalGlobalTheme from "./ModalGlobalTheme";

var PageGlobalThemeButton = function PageGlobalThemeButton(_ref) {
  var allThemes = _ref.allThemes,
      currentTheme = _ref.currentTheme,
      saveCurrentTheme = _ref.saveCurrentTheme;

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      themeVisible = _useState2[0],
      setThemeVisible = _useState2[1];

  var handleClick = function handleClick() {
    setThemeVisible(true);
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "formbuild-btn-opt-default-color",
    onClick: function onClick() {
      return handleClick();
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(IconButton, {
    icon: /*#__PURE__*/React.createElement(ThemeIcon, null)
  }))), /*#__PURE__*/React.createElement(ModalGlobalTheme, {
    visible: themeVisible,
    handleVisible: setThemeVisible
  }));
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    saveCurrentTheme: function saveCurrentTheme(payload) {
      dispatch({
        type: 'style/saveCurrentTheme',
        payload: payload
      });
    }
  };
};

export default connect(function (state) {
  var _state$style, _state$style2;

  return {
    allThemes: state === null || state === void 0 ? void 0 : (_state$style = state.style) === null || _state$style === void 0 ? void 0 : _state$style.allThemes,
    currentTheme: state === null || state === void 0 ? void 0 : (_state$style2 = state.style) === null || _state$style2 === void 0 ? void 0 : _state$style2.currentTheme
  };
}, mapDispatchToProps)(PageGlobalThemeButton);
//# sourceMappingURL=PageGlobalThemeButton.js.map