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 = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { Fragment, useContext, useEffect, useState } from 'react';
import './style/index.less';
import { IconFont, BizGlobalDataContext, ajax } from '@zgfe/business-lib';
import { Drawer, Tooltip, Empty, Button, message } from 'antd';
import { getSdk } from '../../utils/index';
import apis from '../../constants/api';
export var classPrefix = 'data-measure-details';
var DataMeasureDetails = function DataMeasureDetails(_ref) {
  var open = _ref.open,
    setOpen = _ref.setOpen,
    deatilsData = _ref.deatilsData,
    time = _ref.time;
  var _useContext = useContext(BizGlobalDataContext),
    basicConfig = _useContext.basicConfig;
  // 当前选中的错误日志 序列
  var _useState = useState(0),
    _useState2 = _slicedToArray(_useState, 2),
    current = _useState2[0],
    setCurrent = _useState2[1];
  // 当前选中的错误日志 详细数据
  var _useState3 = useState({}),
    _useState4 = _slicedToArray(_useState3, 2),
    currentListItem = _useState4[0],
    setCurrentListItem = _useState4[1];
  var dataMeasure = deatilsData.dataMeasure,
    list = deatilsData.list;
  useEffect(function () {
    if (list && list.length > 0) {
      setCurrentListItem(list[0]);
    }
  }, [deatilsData]);
  var onDownload = function onDownload() {
    var _sdk = getSdk(dataMeasure.sdk, basicConfig) || 0;
    var data = {
      appId: dataMeasure.appId,
      eventName: dataMeasure.eventName,
      beginDate: time === null || time === void 0 ? void 0 : time.begin,
      endDate: time === null || time === void 0 ? void 0 : time.end,
      sdk: _sdk
    };
    ajax(apis.exportReportApi, {
      method: 'post',
      data: data,
      responseType: 'blob',
      fileName: '用户埋点测试报告',
      getResponse: true
    }).then(function (res) {
      if (res !== 'error') {
        message.success('导出成功！');
      }
    });
  };
  return /*#__PURE__*/React.createElement(Drawer, {
    title: /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, "\u5165\u5E93\u8BE6\u60C5"), /*#__PURE__*/React.createElement(IconFont, {
      type: "qingchu",
      onClick: function onClick() {
        return setOpen(false);
      }
    })),
    width: 816,
    placement: 'right',
    className: classPrefix,
    closable: false,
    onClose: function onClose() {
      return setOpen(false);
    },
    open: open
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-title")
  }, "\u57CB\u70B9\u4FE1\u606F"), /*#__PURE__*/React.createElement("ol", {
    className: "".concat(classPrefix, "-ol-top")
  }, /*#__PURE__*/React.createElement("li", {
    className: "event_name"
  }, /*#__PURE__*/React.createElement("div", null, "\u4E8B\u4EF6\u540D\u79F0"), /*#__PURE__*/React.createElement(Tooltip, {
    placement: "top",
    title: dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventName
  }, /*#__PURE__*/React.createElement("div", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventName))), /*#__PURE__*/React.createElement("li", {
    className: "event_name"
  }, /*#__PURE__*/React.createElement("div", null, "\u4E8B\u4EF6\u522B\u540D"), /*#__PURE__*/React.createElement(Tooltip, {
    placement: "top",
    title: dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventNameAlias
  }, /*#__PURE__*/React.createElement("div", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventNameAlias))), /*#__PURE__*/React.createElement("li", null, "SDK\u7C7B\u578B", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.sdk)))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-title")
  }, "\u4E0A\u62A5\u7EDF\u8BA1"), /*#__PURE__*/React.createElement("ol", {
    className: "".concat(classPrefix, "-ol-bottom")
  }, /*#__PURE__*/React.createElement("li", null, "\u65F6\u95F4\u8303\u56F4", /*#__PURE__*/React.createElement("span", null, "".concat(time === null || time === void 0 ? void 0 : time.begin, "~").concat(time === null || time === void 0 ? void 0 : time.end))), /*#__PURE__*/React.createElement("li", null, "\u5165\u5E93\u6761\u6570", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.successCount)), /*#__PURE__*/React.createElement("li", null, "\u9519\u8BEF\u6761\u6570", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.errorCount)), /*#__PURE__*/React.createElement("li", null, "\u5C5E\u6027\u9519\u8BEF\u6761\u6570", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.errorProCount)), /*#__PURE__*/React.createElement("li", null, "\u4E0D\u7B26\u5408\u81EA\u5B9A\u4E49\u6821\u9A8C\u89C4\u5219\u6761\u6570", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.verifyErrorCount)), /*#__PURE__*/React.createElement("li", null, "\u6E05\u6D17\u6761\u6570", /*#__PURE__*/React.createElement("span", null, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.rinseCount)))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-title")
  }, "\u9519\u8BEF\u8BE6\u60C5"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, "\u9ED8\u8BA4\u5C55\u793A\u6700\u8FD1\u768410\u6761\u9519\u8BEF\u65E5\u5FD7"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    onClick: function onClick() {
      return onDownload();
    }
  }, "\u5BFC\u51FA\u62A5\u544A"), /*#__PURE__*/React.createElement(Button, {
    type: "link",
    onClick: function onClick() {
      return window.open('https://docs.zhugeio.com/datamanager/Data_entry_query.html');
    }
  }, "\u67E5\u770B\u6821\u9A8C\u89C4\u5219")))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-log-list")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-log-list-header")
  }, /*#__PURE__*/React.createElement(Tooltip, {
    placement: "top",
    title: dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventName
  }, /*#__PURE__*/React.createElement("div", {
    className: "text_cut_one"
  }, dataMeasure === null || dataMeasure === void 0 ? void 0 : dataMeasure.eventName)), /*#__PURE__*/React.createElement("div", null, "\u539F\u59CB\u65E5\u5FD7", /*#__PURE__*/React.createElement("span", null, "\u65E5\u5FD7\u65F6\u95F4\uFF1A", list && list.length > 0 ? currentListItem.logUtcDate : '-'))), list && list.length > 0 && /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-log-list-box")
  }, /*#__PURE__*/React.createElement("div", null, list.map(function (item, index) {
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: "".concat(index === current && 'active'),
      onClick: function onClick() {
        setCurrent(index);
        setCurrentListItem(list[index]);
      }
    }, /*#__PURE__*/React.createElement("div", null, index === current ? /*#__PURE__*/React.createElement("svg", {
      xmlns: "http://www.w3.org/2000/svg",
      width: "9",
      height: "8",
      viewBox: "0 0 9 8",
      fill: "none"
    }, /*#__PURE__*/React.createElement("ellipse", {
      cx: "4.07165",
      cy: "4",
      rx: "4.01794",
      ry: "4",
      fill: "#D0DFFF"
    }), /*#__PURE__*/React.createElement("ellipse", {
      cx: "4.07196",
      cy: "4",
      rx: "2.00897",
      ry: "2",
      fill: "#165DFF"
    })) : /*#__PURE__*/React.createElement("svg", {
      xmlns: "http://www.w3.org/2000/svg",
      width: "9",
      height: "8",
      viewBox: "0 0 9 8",
      fill: "none"
    }, /*#__PURE__*/React.createElement("ellipse", {
      cx: "4.07165",
      cy: "4",
      rx: "4.01794",
      ry: "4",
      fill: "#FEDDDA"
    }), /*#__PURE__*/React.createElement("ellipse", {
      cx: "4.07196",
      cy: "4",
      rx: "2.00897",
      ry: "2",
      fill: "#E24C40"
    })), item.logUtcDate), /*#__PURE__*/React.createElement(Tooltip, {
      overlayClassName: "".concat(classPrefix, "-log-list-box-tips"),
      placement: "right",
      title: /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, "\u9519\u8BEF\u63CF\u8FF0\uFF1A", item.errorMsg), /*#__PURE__*/React.createElement("div", null, "\u4F18\u5316\u5EFA\u8BAE\uFF1A", item.errorSuggestion))
    }, item.errorMsg && /*#__PURE__*/React.createElement("div", null, item.errorMsg), !item.errorMsg && /*#__PURE__*/React.createElement(Empty, {
      image: Empty.PRESENTED_IMAGE_SIMPLE,
      description: "\u6682\u65E0\u6570\u636E"
    })));
  })), /*#__PURE__*/React.createElement("div", null, " ", currentListItem.dataJson, " "))), (!list || list.length <= 0) && /*#__PURE__*/React.createElement("div", {
    className: "list-empty"
  }, /*#__PURE__*/React.createElement(Empty, {
    image: Empty.PRESENTED_IMAGE_SIMPLE,
    description: "\u6682\u65E0\u6570\u636E"
  })));
};
export default DataMeasureDetails;