"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = _default;

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

var _classnames = _interopRequireDefault(require("classnames"));

var _avatar = _interopRequireDefault(require("../../../../../avatar"));

var _context = require("../../../../context");

var _dialogConfirm = _interopRequireWildcard(require("../../../../../dialog-confirm"));

var _requestApis = require("../../../../request-apis");

var _statusTime = _interopRequireDefault(require("../../../../../status-time"));

var _precls = _interopRequireDefault(require("../../precls"));

var _progress = _interopRequireDefault(require("../../../../../progress"));

var _getProcessColor = _interopRequireDefault(require("../get-process-color"));

var _auth = require("../../../../../../utils/auth");

var _tooltip = _interopRequireDefault(require("../../../../../tooltip"));

var _tooltipText = _interopRequireDefault(require("../../../../../tooltip/tooltip-text"));

var _platform = require("../../../../../../utils/platform");

var _drawerManager = _interopRequireDefault(require("../../../../../drawer-manager"));

var _helpers = require("../../../../../../utils/helpers");

var _getLocale = require("../../../../../../utils/getLocale");

var _bsGlobal = require("../../../../../../utils/bs-global");

require("./index.css");

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 _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; }

function _default(props) {
  var _okrInfo$authority, _okrInfo$aiteUsers, _data$principalUser, _data$principalUser2;

  var index = props.index,
      title = props.title,
      data = props.data,
      createUserId = props.createUserId,
      _props$krAiteUsers = props.krAiteUsers,
      krAiteUsers = _props$krAiteUsers === void 0 ? [] : _props$krAiteUsers,
      _props$hasProgress = props.hasProgress,
      hasProgress = _props$hasProgress === void 0 ? true : _props$hasProgress,
      _props$hasRelation = props.hasRelation,
      hasRelation = _props$hasRelation === void 0 ? true : _props$hasRelation,
      _props$hasPrinciple = props.hasPrinciple,
      hasPrinciple = _props$hasPrinciple === void 0 ? true : _props$hasPrinciple;

  var _useState = (0, _react.useState)(false),
      _useState2 = _slicedToArray(_useState, 2),
      unConnectVisible = _useState2[0],
      setUnConnectVisible = _useState2[1];

  var _useState3 = (0, _react.useState)(data.status === 2),
      _useState4 = _slicedToArray(_useState3, 1),
      isGray = _useState4[0];

  var _useContext = (0, _react.useContext)(_context.CommonContext),
      okrInfo = _useContext.okrInfo;

  var _useContext2 = (0, _react.useContext)(_context.EListContext),
      refreshEList = _useContext2.refreshEList;

  var isParticipant = ((_okrInfo$authority = okrInfo.authority) === null || _okrInfo$authority === void 0 ? void 0 : _okrInfo$authority.roleRelation) && okrInfo.authority.roleRelation.roleType === 2 || !!((_okrInfo$aiteUsers = okrInfo.aiteUsers) !== null && _okrInfo$aiteUsers !== void 0 && _okrInfo$aiteUsers.find(function (item) {
    return (0, _bsGlobal.getUserInfo)().Id == item;
  })) || !!(krAiteUsers !== null && krAiteUsers !== void 0 && krAiteUsers.find(function (item) {
    return (0, _bsGlobal.getUserInfo)().Id == item;
  }));
  var hasRelativeAuth = new _auth.KRAuth({
    user: data.user,
    createUserId: createUserId
  }).hasAuth() || new _auth.OAuth({
    principalUser: okrInfo.principalUser,
    createUserId: okrInfo.createUserId
  }).hasAuth(); // const onEditUserHandler = ([user]) => {
  //   updateTaskPrincipal({task_id: data.taskId, to_user_id: user.data.userId}).then(resp => {
  //     console.log(resp)
  //   })
  //   console.log(user)
  // }

  var onSureUnConnectHandler = function onSureUnConnectHandler() {
    (0, _requestApis.cancelRel)({
      krId: data.mileStoneId,
      objType: data.objType,
      okrId: okrInfo.workId,
      taskId: data.id
    }).then(function (resp) {
      if (resp.Code === 1) {
        refreshEList();
      }
    });
    setUnConnectVisible(false);
  };

  var openProjectDetail = function openProjectDetail() {
    if ((0, _platform.isPlatform)("dd")) {
      _drawerManager["default"].close();
    }

    window.open(window.location.href.replace(location.hash, "#work?iTalentNavCode=tita-work&work_id=".concat(data.id)));
  };

  var workApplyType = data.workApplyType,
      workApplyStatus = data.workApplyStatus;
  var isCreate = (workApplyStatus === 1 || workApplyStatus === 3 || workApplyStatus === 4) && workApplyType === 48;
  return /*#__PURE__*/_react["default"].createElement("div", {
    key: index,
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-prefix"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "tu-icon-Add-xiangmu"
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-title ")),
    onClick: openProjectDetail
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-title-name "))
  }, /*#__PURE__*/_react["default"].createElement(_tooltipText["default"], {
    text: (0, _helpers.escapeHtml)(title),
    isPercent: true
  })), isCreate && /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-title-approvaling"))
  }, (0, _getLocale.getLocale)('Pro_MyS_Establishment'))), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-actions"))
  }, hasPrinciple && /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-actions-user"))
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"].Text, {
    name: data === null || data === void 0 ? void 0 : (_data$principalUser = data.principalUser) === null || _data$principalUser === void 0 ? void 0 : _data$principalUser.name,
    id: data === null || data === void 0 ? void 0 : (_data$principalUser2 = data.principalUser) === null || _data$principalUser2 === void 0 ? void 0 : _data$principalUser2.userId,
    width: 64,
    extraCls: isGray && "".concat(_precls["default"], "__e-project-node-gray")
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-actions-date"))
  }, /*#__PURE__*/_react["default"].createElement(_statusTime["default"], {
    deadLine: data.deadLine,
    isComplete: data.status === 2
  })), hasProgress && /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-actions-progress ").concat(isGray && "".concat(_precls["default"], "__e-project-node-gray")))
  }, /*#__PURE__*/_react["default"].createElement(_progress["default"].Circle, {
    size: 22,
    width: 3,
    percent: data.progress,
    linear: true,
    linearId: data.taskId,
    linearStartColor: (0, _getProcessColor["default"])(data.riskLevel, "linearStartColor", data.status),
    linearEndColor: (0, _getProcessColor["default"])(data.riskLevel, "linearEndColor", data.status),
    backgroundColor: (0, _getProcessColor["default"])(data.riskLevel, "backgroundColor", data.status)
  })), okrInfo.status === 1 && hasRelation && (hasRelativeAuth || isParticipant) ? /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: (0, _getLocale.getLocale)("OKR_MyO_Text_Cancel"),
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(_precls["default"], "__e-project-node-actions-connect")),
    onClick: function onClick() {
      return setUnConnectVisible(true);
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "tu-icon-quxiaoguanlian e-node-status-icon"
  }))) : null), /*#__PURE__*/_react["default"].createElement(_dialogConfirm["default"], {
    visible: unConnectVisible,
    type: "warning"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    type: "title"
  }, (0, _getLocale.getLocale)("OKR_MyO_Text_Cancelass")), /*#__PURE__*/_react["default"].createElement("span", {
    type: "content"
  }, (0, _getLocale.getLocale)("OKR_MyO_Text_TitemnotO")), /*#__PURE__*/_react["default"].createElement(_dialogConfirm.CancelButton, {
    type: "button",
    onClick: function onClick() {
      return setUnConnectVisible(false);
    }
  }, (0, _getLocale.getLocale)("Mod_Cancel")), /*#__PURE__*/_react["default"].createElement(_dialogConfirm.SureButton, {
    type: "button",
    onClick: onSureUnConnectHandler
  }, (0, _getLocale.getLocale)("OKR_MyO_Butt_Determine"))));
}