import React from "react";
import { i18n } from '@fishx/i18n';
import { useHandler } from "../../../../hooks/useHandler";
import { connect } from "../../../redux";
import { set, get } from "dot-prop-immutable";
import styled from "styled-components";
import { SimpleForm as Form, Radio } from '@whalecloud/fdx';
import { getActiveElementWithChildren } from "../../../selectors";
import { ReactComponent as AlignCenterIcon } from "@svgr/webpack!../../../assets/icons/format_align_center.svg";
import { ReactComponent as AlignLeftIcon } from "@svgr/webpack!../../../assets/icons/format_align_left.svg";
import { ReactComponent as AlignJustifyIcon } from "@svgr/webpack!../../../assets/icons/format_align_justify.svg";
import { ReactComponent as AlignRightIcon } from "@svgr/webpack!../../../assets/icons/format_align_right.svg";
import { toolFormAttr } from "../../../utils";
var FormContainer = /*#__PURE__*/styled("div", {
  target: "e1fovp370",
  label: "FormContainer"
})({
  padding: 5,
  svg: {
    width: 18
  }
});
var root = 'data.settings';
var alignments = [{
  label: /*#__PURE__*/React.createElement(AlignLeftIcon, null),
  value: 'left'
}, {
  label: /*#__PURE__*/React.createElement(AlignCenterIcon, null),
  value: 'center'
}, {
  label: /*#__PURE__*/React.createElement(AlignRightIcon, null),
  value: 'right'
}, {
  label: /*#__PURE__*/React.createElement(AlignJustifyIcon, null),
  value: 'justify'
}];

var HorizontalAlignAction = function HorizontalAlignAction(props) {
  var element = props.element;
  var align = get(element, "data.settings.horizontalAlign") || "left";
  var initialValues = {
    horizontalAlign: align
  };
  var onFormChange = useHandler(props, function (_ref) {
    var element = _ref.element,
        updateElement = _ref.updateElement;
    return function (obj) {
      updateElement({
        element: set(element, "".concat(root, ".horizontalAlign"), obj['horizontalAlign'])
      });
    };
  });
  return /*#__PURE__*/React.createElement(FormContainer, null, /*#__PURE__*/React.createElement(Form, Object.assign({}, toolFormAttr, {
    initialValues: initialValues,
    onValuesChange: onFormChange
  }), /*#__PURE__*/React.createElement(Form.Item, {
    label: i18n('PAGEBUIDER_SETTINGS_HORIZONTAL_ALIGN'),
    name: "horizontalAlign"
  }, /*#__PURE__*/React.createElement(Radio.Group, {
    size: "small"
  }, alignments.map(function (align) {
    return /*#__PURE__*/React.createElement(Radio.Button, {
      key: "horizontalAlign_".concat(align.value),
      value: align.value
    }, align.label);
  })))));
};

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

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