import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from "react";
import { connect } from "../../../redux";
import { getActiveElement } from "../../../selectors";
import CodeDrawer from "../../../components/CodeDrawer";
import { Row, Col, Button } from '@whalecloud/fdx';

var CommonCodeDrawer = function CommonCodeDrawer(props) {
  var value = props.value,
      onClose = props.onClose,
      title = props.title,
      buttonText = props.buttonText,
      buttonLabel = props.buttonLabel,
      language = props.language;

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

  var handleOpen = function handleOpen() {
    setDrawVisible(true);
  };

  var handleClose = function handleClose(code) {
    setDrawVisible(false);
    var formatCode = JSON.parse(code);
    onClose(formatCode);
  };

  var withLabel = buttonLabel ? 16 : 24;
  return /*#__PURE__*/React.createElement(Row, {
    span: 24
  }, buttonLabel && /*#__PURE__*/React.createElement(Col, {
    span: 8,
    style: {
      textAlign: 'right',
      fontSize: '14px',
      paddingRight: '8px'
    }
  }, buttonLabel), /*#__PURE__*/React.createElement(Col, {
    span: withLabel,
    style: {
      paddingBottom: '10px'
    }
  }, /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    onClick: handleOpen
  }, buttonText), /*#__PURE__*/React.createElement(CodeDrawer, {
    destroyOnClose: true,
    drawVisible: drawVisible,
    value: value,
    language: language,
    onClose: handleClose,
    title: title
  })));
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    updateElement: function updateElement(payload) {
      dispatch({
        type: 'appBuilder/updateAndFlattenElement',
        payload: payload
      });
    }
  };
};

export default connect(function (state) {
  return {
    element: getActiveElement(state)
  };
}, mapDispatchToProps)(CommonCodeDrawer);
//# sourceMappingURL=CommonCodeDrawer.js.map