import React from 'react';
import { connect } from "../../../redux";
import { useHandler } from "../../../../hooks/useHandler";
import { Radio } from "@whalecloud/fdx";
import { set } from "dot-prop-immutable";
import { getActiveElementId, getElementWidthChildren, getElements } from "../../../selectors";

var SwitchCondition = function SwitchCondition(props) {
  var _element$data;

  var element = props.element;

  if (!element || (element === null || element === void 0 ? void 0 : element.type) !== 'if') {
    return null;
  }

  var _element$data$compone = (_element$data = element.data) === null || _element$data === void 0 ? void 0 : _element$data.componentSettings,
      _element$data$compone2 = _element$data$compone.currentCondition,
      currentCondition = _element$data$compone2 === void 0 ? 'all' : _element$data$compone2;

  var onChange = useHandler(props, function (_ref) {
    var element = _ref.element,
        updateElement = _ref.updateElement;
    return function (e) {
      var newElement = set(element, "data.componentSettings.currentCondition", e.target.value);
      updateElement({
        element: newElement
      });
    };
  });
  return /*#__PURE__*/React.createElement(Radio.Group, {
    className: "pb-editor-if-setting",
    onChange: onChange,
    value: currentCondition
  }, /*#__PURE__*/React.createElement(Radio, {
    value: "all"
  }), /*#__PURE__*/React.createElement(Radio, {
    value: true
  }), /*#__PURE__*/React.createElement(Radio, {
    value: false
  }));
};

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

export default connect(function (state) {
  var activeElementId = getActiveElementId(state);
  var elements = getElements(state);

  if (!elements[activeElementId]) {
    activeElementId = null;
  }

  return {
    element: activeElementId ? getElementWidthChildren(state, activeElementId) : null
  };
}, mapDispatchToProps)(SwitchCondition);
//# sourceMappingURL=SwitchCondition.js.map