"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"] = void 0;

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

var _renders = require("./renders");

var _hooks = require("./hooks");

var _tableExcel = _interopRequireDefault(require("../table-excel"));

var _hooks2 = require("../../utils/hooks");

var _popupSelect = _interopRequireDefault(require("../popup-select"));

require("ag-grid-community/styles/ag-grid.css");

require("ag-grid-community/styles/ag-theme-material.css");

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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 defaultColumnOption = {
  resizable: true,
  editable: false
};
var defaultSpanOption = {
  rowSpan: function rowSpan(_ref) {
    var _ref$data$rowSpan = _ref.data.rowSpan,
        _rowSpan = _ref$data$rowSpan === void 0 ? 0 : _ref$data$rowSpan;

    return _rowSpan;
  },
  cellClassRules: {
    'cell-span': 'data.rowSpan > 1'
  }
};
var preCls = 'tita-okr-excel';

var App = function App(_ref2) {
  var showCycle = _ref2.showCycle,
      data = _ref2.data,
      onRefresh = _ref2.onRefresh;
  var dicData = (0, _hooks.dic)();
  var okrColumnOptions = (0, _react.useMemo)(function () {
    return [_objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['目标（O）'],
      width: 400,
      valueGetter: 'data.workName',
      pinned: 'left',
      // autoHeight: true,
      wrapText: true,
      cellRenderer: (0, _renders.OkrNameRenderer)(showCycle, onRefresh)
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['类型'],
      valueGetter: 'data.okrType',
      hide: true,
      width: 100,
      cellRenderer: _renders.okrTypeRenderer
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['负责人'],
      valueGetter: 'data.principalUser.name',
      hide: true,
      width: 100,
      cellRenderer: _renders.userRenderer
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['对齐目标负责人'],
      valueGetter: 'data.parentPrincipal.principalName',
      width: 120,
      hide: true
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['可见范围'],
      valueGetter: 'data.visibility',
      width: 100,
      hide: true,
      cellRenderer: _renders.visibilityRenderer
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['目标完成度'],
      valueGetter: 'data.progress',
      width: 120,
      cellRenderer: _renders.TaskProgressRenderer
    }), _objectSpread(_objectSpread(_objectSpread({}, defaultColumnOption), defaultSpanOption), {}, {
      field: dicData['目标最新进展'],
      valueGetter: 'data.progressDescription',
      cellRenderer: _renders.tooltipRenderer,
      width: 200,
      hide: true
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['关键成果（KR）'],
      valueGetter: 'data.Kr.mileStoneName',
      width: 400,
      cellRenderer: (0, _renders.krNameRenderer)(onRefresh)
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['KR 负责人'],
      valueGetter: 'data.Kr.user.name',
      width: 100,
      hide: true,
      cellRenderer: _renders.krUserRenderer
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['权重'],
      valueGetter: 'data.Kr.krWeight',
      width: 80,
      hide: true,
      cellRenderer: _renders.krWeightRenderer
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['信心指数'],
      valueGetter: 'data.Kr.confidenceIndex',
      width: 80,
      cellRenderer: _renders.ConfidenceRenderer
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['KR 完成度'],
      valueGetter: 'data.Kr.progress',
      width: 120,
      cellRenderer: _renders.KrProgressRenderer
    }), _objectSpread(_objectSpread({}, defaultColumnOption), {}, {
      field: dicData['KR 最新进展'],
      valueGetter: 'data.Kr.progressDescription',
      cellRenderer: _renders.tooltipHtmlRenderer,
      width: 200
    })];
  }, [showCycle]);

  var _useOkrColumns = (0, _hooks.useOkrColumns)(okrColumnOptions),
      columnDefs = _useOkrColumns.columnDefs,
      onColumnMoved = _useOkrColumns.onColumnMoved,
      onColumnResized = _useOkrColumns.onColumnResized,
      columnCtlData = _useOkrColumns.columnCtlData,
      onColumnsHideOrShow = _useOkrColumns.onColumnsHideOrShow;

  var getRowId = (0, _react.useMemo)(function () {
    return function (params) {
      return params.data.workId || params.data.feedId + params.data.Kr.mileStoneId;
    };
  }, []);
  var onColumnMovedHandler = (0, _react.useCallback)(function (event) {
    var moveField = event.column.colId;
    var toIndex = event.toIndex;
    onColumnMoved(moveField, toIndex);
  }, [onColumnMoved]);
  var onColumnResizedHandler = (0, _hooks2.useDebounceFn)(function (event) {
    var _event$column = event.column,
        actualWidth = _event$column.actualWidth,
        colId = _event$column.colId;
    onColumnResized(colId, actualWidth);
  }, {
    wait: 200
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "ag-theme-material ".concat(preCls)
  }, /*#__PURE__*/_react["default"].createElement(_popupSelect["default"], {
    menuData: columnCtlData,
    popupPlacement: "bottomLeft",
    action: "click",
    mode: "checkbox",
    height: 292,
    onChange: onColumnsHideOrShow,
    autoClose: false
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__column-ctl")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "tu-icon-APP-shezhi"
  }))), /*#__PURE__*/_react["default"].createElement(_tableExcel["default"], {
    headerHeight: 40,
    rowHeight: 38,
    suppressRowTransform: true,
    enableRangeSelection: true,
    domLayout: "autoHeight",
    getRowId: getRowId,
    rowData: data,
    columnDefs: columnDefs,
    detailRowAutoHeight: true,
    onColumnMoved: onColumnMovedHandler,
    onColumnResized: onColumnResizedHandler.run
  }));
};

var _default = App;
exports["default"] = _default;