"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HypothesisNode = void 0;

var _react = _interopRequireWildcard(require("react"));

var _all = require("react-icons/all");

var _clsx = _interopRequireDefault(require("clsx"));

var _hypothesisBar = require("./hypothesis-bar");

var _hypothesisHeader = require("./hypothesis-header");

var _jsxRuntime = require("react/jsx-runtime");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var UNKNOWN_TYPE = "unknown_type";

var HypothesisNode = function HypothesisNode(props) {
  var node = props.node,
      setModalIsOpen = props.setModalIsOpen,
      setSelectedNode = props.setSelectedNode,
      setCreateHypothesisModalIsOpen = props.setCreateHypothesisModalIsOpen;

  if (node == null) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      children: "empty"
    });
  }

  var isRoot = node.type === "root" || node.parent_id == null;
  var type = node.type || UNKNOWN_TYPE;

  var handleOpenModal = function handleOpenModal() {
    setSelectedNode(node);
    setModalIsOpen(true);
  };

  var handlerOpenCreateHypothesisModal = function handlerOpenCreateHypothesisModal() {
    setSelectedNode(node);
    setCreateHypothesisModalIsOpen(true);
  };

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    children: [isRoot && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "flex items-center text-base font-semibold mb-5",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
        className: "text-dark-gray mr-3 text-2xl",
        children: "Action plan"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
        type: "button",
        className: "btn-round btn-round-primary btn-round-sm",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_all.BsPlusLg, {})
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "w-full",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "w-full mb-0.5",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_hypothesisBar.HypothesisBar, {
          hypothesis: node,
          onTitleClick: handleOpenModal
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: (0, _clsx.default)({
          "bg-light-blue p-5 mt-3 rounded-8px border border-dashed": isRoot,
          "pl-7 my-2.5": !isRoot
        }),
        children: [node.children.map(function (item) {
          return /*#__PURE__*/(0, _react.createElement)(HypothesisNode, _objectSpread(_objectSpread({}, props), {}, {
            node: item,
            key: item.id
          }));
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_hypothesisHeader.HypothesisBlockHeader, _objectSpread(_objectSpread({
          title: "",
          onButtonClick: handlerOpenCreateHypothesisModal,
          className: "mb-2.5"
        }, type === "root" ? {
          title: "Add new issue",
          noResultsTitle: "No issues created yet"
        } : {}), type === "factor" ? {
          title: "Add new potential solution",
          noResultsTitle: "No potential solutions created yet"
        } : {}))]
      })]
    })]
  });
};

exports.HypothesisNode = HypothesisNode;