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 = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { IconFont } from '@zgfe/business-lib';
import { Select } from 'antd';
import React, { useEffect, useState } from 'react';
var JoinConditionRow = function JoinConditionRow(_ref) {
  var _value$, _value$2;
  var tableA = _ref.tableA,
    tableB = _ref.tableB,
    value = _ref.value,
    id = _ref.id,
    removeAble = _ref.removeAble,
    onChange = _ref.onChange,
    onRemove = _ref.onRemove;
  var classPrefix = 'flow-join-config';
  var _useState = useState(),
    _useState2 = _slicedToArray(_useState, 2),
    a = _useState2[0],
    setA = _useState2[1];
  var _useState3 = useState(),
    _useState4 = _slicedToArray(_useState3, 2),
    b = _useState4[0],
    setB = _useState4[1];
  var _useState5 = useState(),
    _useState6 = _slicedToArray(_useState5, 2),
    columnsA = _useState6[0],
    setColumnsA = _useState6[1];
  var _useState7 = useState(),
    _useState8 = _slicedToArray(_useState7, 2),
    columnsB = _useState8[0],
    setColumnsB = _useState8[1];
  var _useState9 = useState(true),
    _useState10 = _slicedToArray(_useState9, 2),
    enableAdd = _useState10[0],
    setEnableAdd = _useState10[1];
  useEffect(function () {
    setA(value ? value[0] : undefined);
    setB(value ? value[1] : undefined);
  }, []);
  useEffect(function () {
    if (onChange) onChange([a, b], id, enableAdd);
    if (a && b) setEnableAdd(false);
  }, [a, b]);
  useEffect(function () {
    setColumnsA(tableA === null || tableA === void 0 ? void 0 : tableA.columns.filter(function (column) {
      return !b || b.type === column.type;
    }));
  }, [tableA, b]);
  useEffect(function () {
    setColumnsB(tableB === null || tableB === void 0 ? void 0 : tableB.columns.filter(function (column) {
      return !a || a.type === column.type;
    }));
  }, [tableB, a]);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-row")
  }, /*#__PURE__*/React.createElement(Select, {
    className: "".concat(classPrefix, "-row-column"),
    options: columnsA,
    defaultValue: value === null || value === void 0 ? void 0 : (_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.name,
    value: a === null || a === void 0 ? void 0 : a.name,
    onChange: function onChange(e, column) {
      setA(column);
    },
    fieldNames: {
      label: 'name',
      value: 'name'
    }
  }), /*#__PURE__*/React.createElement("span", {
    className: "".concat(classPrefix, "-row-operator")
  }, "="), /*#__PURE__*/React.createElement(Select, {
    className: "".concat(classPrefix, "-row-column"),
    options: columnsB,
    defaultValue: value === null || value === void 0 ? void 0 : (_value$2 = value[1]) === null || _value$2 === void 0 ? void 0 : _value$2.name,
    value: b === null || b === void 0 ? void 0 : b.name,
    onChange: function onChange(e, column) {
      setB(column);
    },
    fieldNames: {
      label: 'name',
      value: 'name'
    }
  }), removeAble && (b || a) ? /*#__PURE__*/React.createElement(IconFont, {
    type: "qingchu",
    onClick: function onClick() {
      if (onRemove) onRemove(id);
    }
  }) : null);
};
export default JoinConditionRow;