function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Input, Modal, Tag, Alert, Row, Col } from 'mkui-fd';
import classNames from 'classnames';
var btns = [{
  code: '+',
  name: '+',
  isOperator: true
}, {
  code: 7,
  name: 7,
  isOperator: false
}, {
  code: 8,
  name: 8,
  isOperator: false
}, {
  code: 9,
  name: 9,
  isOperator: false
}, {
  code: 'C',
  name: 'C',
  isOperator: true
}, {
  code: '-',
  name: '-',
  isOperator: true
}, {
  code: 4,
  name: 4,
  isOperator: false
}, {
  code: 5,
  name: 5,
  isOperator: false
}, {
  code: 6,
  name: 6,
  isOperator: false
}, {
  code: '=',
  name: '=',
  isOperator: true
}, {
  code: '*',
  name: '*',
  isOperator: true
}, {
  code: 1,
  name: 1,
  isOperator: false
}, {
  code: 2,
  name: 2,
  isOperator: false
}, {
  code: 3,
  name: 3,
  isOperator: false
}, {
  code: '%',
  name: '%',
  isOperator: true
}, {
  code: '/',
  name: '/',
  isOperator: true
}, {
  code: '00',
  name: '00',
  isOperator: false
}, {
  code: 0,
  name: 0,
  isOperator: false
}, {
  code: '.',
  name: '.',
  isOperator: false
}, {
  code: 'D',
  name: 'D',
  isOperator: true
}];

var ExpressionBuilder = function ExpressionBuilder(_ref) {
  var prefixCls = _ref.prefixCls,
      dataSource = _ref.dataSource;

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

  var _useState3 = useState(dataSource),
      _useState4 = _slicedToArray(_useState3, 2),
      store = _useState4[0],
      setStore = _useState4[1];

  var _useState5 = useState([]),
      _useState6 = _slicedToArray(_useState5, 2),
      formulaQueue = _useState6[0],
      setFormulaQueue = _useState6[1];

  var selectedHandle = function selectedHandle(item) {
    setStore(function (store) {
      return store.filter(function (s) {
        return s.code !== item.code;
      });
    });
    pushFormulaQueue(item);
  };

  var pushFormulaQueue = function pushFormulaQueue(item) {
    setFormulaQueue(function (formula) {
      return [].concat(_toConsumableArray(formula), [item]);
    });
  };

  var clearHandle = function clearHandle(item) {
    setFormulaQueue(function (formula) {
      return formula.filter(function (s) {
        return s.code !== item.code;
      });
    });
    setStore(function (store) {
      return [].concat(_toConsumableArray(store), [item]);
    });
  };

  var transformFormula = function transformFormula(queue) {
    var result = '';
    queue.forEach(function (element) {
      result += element.name;
    });
    return result;
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Input, {
    onClick: function onClick() {
      setVisible(true);
    },
    value: transformFormula(formulaQueue)
  }), /*#__PURE__*/React.createElement(Modal, {
    title: "\u516C\u5F0F",
    visible: visible,
    onOk: function onOk() {
      return setVisible(false);
    },
    onCancel: function onCancel() {
      return setVisible(false);
    },
    width: "600px"
  }, /*#__PURE__*/React.createElement(Alert, {
    description: "\u8BF4\u660E\uFF1A\u6DFB\u52A0\u8BA1\u7B97\u516C\u5F0F\u53EF\u7528\u4E8E\u5355\u636E\u5185\u6570\u5B57\u6216\u91D1\u989D\u7684\u81EA\u52A8\u8BA1\u7B97\uFF0C\u4F8B\u5982\uFF1A\u5728\u91C7\u8D2D\u5355\u636E\u4E2D\u6DFB\u52A0\u5355\u4EF7\u3001\u6570\u91CF\u3001\u5408\u8BA1\u5B57\u6BB5\uFF0C\u5E76\u4E3A\u201D\u5408\u8BA1\u201C\u5B57\u6BB5\u6DFB\u52A0\u201C\u8BA1\u7B97\u516C\u5F0F=\u5355\u4EF7x\u6570\u91CF\u201D\uFF0C\u5F53\u586B\u5199\u5355\u4EF7\u548C\u6570\u91CF\u540E\uFF0C\u5408\u8BA1\u5B57\u6BB5\u4E2D\u4F1A\u81EA\u52A8\u586B\u5145\u8BA1\u7B97\u7ED3\u679C\u3002",
    type: "info"
  }), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-bar")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-store")
  }, /*#__PURE__*/React.createElement(Card, {
    title: "\u8BA1\u7B97\u5BF9\u8C61\uFF08\u9650\u6570\u5B57\u3001\u91D1\u989D\u63A7\u4EF6\uFF09"
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-store-content")
  }, store.map(function (item) {
    return /*#__PURE__*/React.createElement(Tag, {
      key: item.code,
      onClick: function onClick() {
        selectedHandle(item);
      }
    }, item.name);
  })))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-cacular")
  }, /*#__PURE__*/React.createElement(Card, {
    title: "\u6570\u5B57\u952E\u76D8"
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-cacular-content")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-options")
  }, btns.map(function (btn) {
    return /*#__PURE__*/React.createElement("div", {
      key: btn.code,
      className: classNames('item', {
        'item-pan': btn.isOperator
      }),
      onClick: function onClick() {
        pushFormulaQueue(btn);
      }
    }, btn.name);
  })))))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-formula")
  }, /*#__PURE__*/React.createElement("span", null, "\u8BA1\u7B97\u516C\u5F0F = "), formulaQueue.map(function (item) {
    if ('isOperator' in item) {
      return item.name;
    }

    return /*#__PURE__*/React.createElement(Tag, {
      key: item.code
    }, item.name);
  }))));
};

var Card = function Card(_ref2) {
  var title = _ref2.title,
      _ref2$prefixCls = _ref2.prefixCls,
      prefixCls = _ref2$prefixCls === void 0 ? 'coustom-card' : _ref2$prefixCls,
      cardStyle = _ref2.cardStyle,
      children = _ref2.children;
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls),
    style: cardStyle
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-title")
  }, title), /*#__PURE__*/React.createElement("div", null, children));
};

ExpressionBuilder.propTypes = {
  prefixCls: PropTypes.string,
  dataSource: PropTypes.array
};
ExpressionBuilder.defaultProps = {
  prefixCls: 'mkui-expression-builder',
  dataSource: []
};
export default ExpressionBuilder;
//# sourceMappingURL=ExpressionBuilder.js.map
