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 _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 _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 _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; }
import React, { useContext } from 'react';
import _ from 'lodash';
import { JsonEditorContext, classPrefix } from '.';
import { IconFont } from '@zgfe/business-lib';
var Value = function Value(_ref) {
  var value = _ref.value;
  if (_.isString(value)) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-value")
    }, "\"".concat(value, "\""));
  }
  if (_.isBoolean(value)) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-value")
    }, value ? 'true' : 'false');
  }
  if (_.isNull(value)) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-value")
    }, "null");
  }
  if (_.isUndefined(value)) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-value")
    }, "undefined");
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-value")
  }, value);
};
var _Symbol = function _Symbol(_ref2) {
  var value = _ref2.value;
  var color;
  //正则判断， {, }, [, ]为蓝色
  if (value.match(/[\{\}\[\]]/)) {
    color = '#165dff';
  }
  return /*#__PURE__*/React.createElement("span", {
    className: "".concat(classPrefix, "-symbal"),
    style: {
      color: color
    }
  }, value);
};
var Row = function Row(_ref3) {
  var label = _ref3.label,
    value = _ref3.value,
    deep = _ref3.deep,
    isArrStart = _ref3.isArrStart,
    isObjectStart = _ref3.isObjectStart,
    isArrEnd = _ref3.isArrEnd,
    isObjectEnd = _ref3.isObjectEnd,
    inArray = _ref3.inArray,
    _ref3$isExpanded = _ref3.isExpanded,
    isExpanded = _ref3$isExpanded === void 0 ? true : _ref3$isExpanded,
    path = _ref3.path;
  var _useContext = useContext(JsonEditorContext),
    setExpandList = _useContext.setExpandList,
    columnExtra = _useContext.columnExtra,
    rowClassName = _useContext.rowClassName,
    labelRender = _useContext.labelRender;
  function getLabel() {
    if (inArray || _.isUndefined(label)) return null;
    if (labelRender) {
      return labelRender(label, path);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-label")
    }, label);
  }
  function onClickRow() {
    if (!path) return;
    setExpandList(function (list) {
      if (list.includes(path)) {
        return list.filter(function (item) {
          return item !== path;
        });
      }
      return [].concat(_toConsumableArray(list), [path]);
    });
  }
  if (!isExpanded && !isArrStart && !isObjectStart) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(classPrefix, "-row ").concat(classPrefix, "-inner"),
      style: {
        paddingLeft: deep ? "".concat(deep * 18, "px") : '8px'
      },
      onClick: onClickRow
    }, "...");
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-row ").concat(rowClassName),
    style: {
      paddingLeft: deep ? "".concat(deep * 18, "px") : '8px'
    },
    onClick: onClickRow
  }, (isObjectStart || isArrStart) && path ? /*#__PURE__*/React.createElement(IconFont, {
    type: "paixu",
    className: "".concat(classPrefix, "-arrow"),
    style: {
      transform: isExpanded ? 'rotate(0deg)' : 'rotate(-90deg)',
      transition: 'transform 0.3s'
    }
  }) : undefined, getLabel(), !isArrEnd && !isObjectEnd && !inArray && label && /*#__PURE__*/React.createElement("span", {
    className: "".concat(classPrefix, "-colon")
  }, /*#__PURE__*/React.createElement(_Symbol, {
    value: ":"
  })), isObjectStart && /*#__PURE__*/React.createElement(_Symbol, {
    value: '{'
  }), isObjectEnd && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Symbol, {
    value: '}'
  }), /*#__PURE__*/React.createElement(_Symbol, {
    value: ','
  })), isArrStart && /*#__PURE__*/React.createElement(_Symbol, {
    value: '['
  }), isArrEnd && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Symbol, {
    value: ']'
  }), /*#__PURE__*/React.createElement(_Symbol, {
    value: ','
  })), !_.isUndefined(value) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Value, {
    value: value
  })), !isArrEnd && !isObjectEnd && !isObjectStart && !isArrStart && /*#__PURE__*/React.createElement(_Symbol, {
    value: ','
  }), columnExtra && columnExtra(label, value, path));
};
export default Row;