function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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),
    _useState0 = _slicedToArray(_useState9, 2),
    enableAdd = _useState0[0],
    setEnableAdd = _useState0[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;