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 from 'react';
import ZModulesCDP from '../../types';
import moment from 'moment';
import { classPrefix } from '.';
import { datasetTypeList } from './components/fusionModal/utils';
import FusionSwitch from './components/switch';
import { Tooltip } from 'antd';
import { BizSelect, IconFont } from '@zgfe/business-lib';
var datasetTypes = [{
  value: 0,
  label: '数据集类型'
}].concat(_toConsumableArray(datasetTypeList));
var statusList = [{
  id: 'all',
  label: '状态'
}, {
  id: ZModulesCDP.DataSet.UpdateState.success,
  label: '成功'
}, {
  id: ZModulesCDP.DataSet.UpdateState.fail,
  label: '失败'
}, {
  id: ZModulesCDP.DataSet.UpdateState.running,
  label: '执行中'
}];
// 更新频率映射
export var updateFrequencyData = ['手动更新', '定时更新', '依赖数据集类型'];
export var getColumns = function getColumns() {
  var authority = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var onChangeParams = arguments.length > 1 ? arguments[1] : undefined;
  var onChangeStatus = arguments.length > 2 ? arguments[2] : undefined;
  var onDelete = arguments.length > 3 ? arguments[3] : undefined;
  var onCheckLog = arguments.length > 4 ? arguments[4] : undefined;
  var onUpdate = arguments.length > 5 ? arguments[5] : undefined;
  var onEdit = arguments.length > 6 ? arguments[6] : undefined;
  return [{
    width: 240,
    title: '数据集名称',
    dataIndex: 'datasetName',
    key: 'datasetName',
    ellipsis: true,
    render: function render(v, record) {
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(classPrefix, "-table-field")
      }, /*#__PURE__*/React.createElement("div", {
        className: "".concat(classPrefix, "-table-field-text"),
        title: v
      }, v), record.needConfig ? /*#__PURE__*/React.createElement(Tooltip, {
        title: "\u7528\u6237\u6807\u8BC6\u5B57\u6BB5\u88AB\u5220\u9664\uFF0C\u8BF7\u91CD\u65B0\u914D\u7F6E"
      }, /*#__PURE__*/React.createElement(IconFont, {
        type: "tishi"
      })) : null);
    }
  }, {
    width: 150,
    className: "".concat(classPrefix, "-table-title"),
    title: /*#__PURE__*/React.createElement(BizSelect, {
      defaultValue: {
        value: 0
      },
      options: datasetTypes,
      keyField: "value",
      onChange: function onChange(data) {
        console.log('type:', data);
        onChangeParams(data.value, 'datasetType');
      }
    }),
    dataIndex: 'datasetType',
    render: function render(v) {
      var txt = '';
      datasetTypeList.forEach(function (item) {
        if (item.value === v) txt = item.label;
      });
      return txt;
    }
  }, {
    width: 180,
    title: '最近更新完成时间',
    dataIndex: 'lastUpdateTime',
    key: 'lastUpdateTime',
    ellipsis: true,
    render: dateRender,
    sorter: function sorter(a, b) {
      return dateSorter(a, b, 'lastUpdateTime');
    }
  }, {
    width: 180,
    title: '下次执行时间',
    dataIndex: 'nextRunTime',
    key: 'nextRunTime',
    ellipsis: true,
    render: dateRender,
    sorter: function sorter(a, b) {
      return dateSorter(a, b, 'nextRunTime');
    }
  }, {
    width: 130,
    title: '更新频率',
    dataIndex: 'updateFrequency',
    render: function render(v, record) {
      if (!v) return '-';
      var txt = updateFrequencyData[((v === null || v === void 0 ? void 0 : v.type) || 1) - 1];
      if (v.type !== ZModulesCDP.DataSet.UpdateType.mumal) {
        return txt;
      }
      var disabled = !authority[1706261694] || [ZModulesCDP.DataSet.TaskStatus.disable, ZModulesCDP.DataSet.TaskStatus.invalid].includes(record.status) || !record.status || record.state === ZModulesCDP.DataSet.UpdateState.running;
      return /*#__PURE__*/React.createElement("a", {
        className: "".concat(classPrefix, "-btn-update ").concat(disabled ? 'disable' : ''),
        onClick: function onClick() {
          if (disabled) return;
          onUpdate(record.id);
        }
      }, txt);
    }
  }, {
    width: 100,
    className: "".concat(classPrefix, "-table-title"),
    title: /*#__PURE__*/React.createElement(BizSelect, {
      defaultValue: {
        id: 'all'
      },
      options: statusList,
      onChange: function onChange(data) {
        onChangeParams(data.id, 'state');
      }
    }),
    dataIndex: 'state',
    key: 'state',
    render: function render(v) {
      return statusNode(v);
    }
  }, {
    width: 120,
    title: '创建人',
    dataIndex: 'creator',
    key: 'creator'
  }, {
    width: 180,
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    render: dateRender,
    sorter: function sorter(a, b) {
      return dateSorter(a, b, 'createTime');
    }
  }, {
    width: 180,
    title: '更新时间',
    dataIndex: 'updateTime',
    render: dateRender,
    sorter: function sorter(a, b) {
      return dateSorter(a, b, 'updateTime');
    }
  }, {
    title: '操作',
    fixed: 'right',
    width: 240,
    render: function render(_, record) {
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(classPrefix, "-options")
      }, record.datasetType !== 3 && /*#__PURE__*/React.createElement(FusionSwitch, {
        task: record,
        onChange: function onChange(status) {
          onChangeStatus(record.id, status);
        }
      }), /*#__PURE__*/React.createElement("a", {
        className: record.status !== ZModulesCDP.DataSet.TaskStatus.enable && authority[1706261692] ? '' : 'disabled',
        onClick: function onClick() {
          if (record.status !== ZModulesCDP.DataSet.TaskStatus.enable && authority[1706261692]) onEdit && onEdit(record.id);
        }
      }, "\u7F16\u8F91"), record.datasetType !== 3 && /*#__PURE__*/React.createElement("a", {
        className: authority[1706261693] ? '' : 'disabled',
        onClick: function onClick() {
          if (!authority[1706261693]) return;
          onCheckLog(record);
        }
      }, "\u65E5\u5FD7"), /*#__PURE__*/React.createElement("a", {
        className: record.status !== ZModulesCDP.DataSet.TaskStatus.enable && authority[1706261690] ? '' : 'disabled',
        onClick: function onClick() {
          if (record.status !== ZModulesCDP.DataSet.TaskStatus.enable && authority[1706261690]) onDelete(record);
        }
      }, "\u5220\u9664"));
    }
  }];
};
export function dateRender(date) {
  if (!date) return '-';
  return moment(date).format('YYYY-MM-DD HH:mm:ss');
}
export function dateSorter(a, b, field) {
  if (!a[field]) return -1;
  if (!b[field]) return 1;
  return moment(a[field]).toDate().getTime() - moment(b[field]).toDate().getTime();
}
export var statusNode = function statusNode(v) {
  switch (v) {
    case ZModulesCDP.DataSet.UpdateState.fail:
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
        className: "".concat(classPrefix, "-state fail")
      }), "\u5931\u8D25");
    case ZModulesCDP.DataSet.UpdateState.success:
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
        className: "".concat(classPrefix, "-state success")
      }), "\u6210\u529F");
    case ZModulesCDP.DataSet.UpdateState.running:
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
        className: "".concat(classPrefix, "-state running")
      }), "\u6267\u884C\u4E2D");
    default:
      return /*#__PURE__*/React.createElement(React.Fragment, null, "\u672A\u5F00\u59CB");
  }
};