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 { Modal, Table } from "antd";
import React, { forwardRef, useImperativeHandle, useMemo, useState } from "react";
import { getText } from "../../../../../../../locales/index";
import { formatDate } from "../../utils/date";
import { copyText } from "../../utils/file";
import "./index.less";
var Detail = function Detail(props, ref) {
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    list = _useState2[0],
    setList = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    open = _useState4[0],
    setOpen = _useState4[1];
  var columns = [{
    title: getText("table-action-export-import-log-name"),
    dataIndex: "file_name"
  }, {
    title: getText("table-action-export-import-log-result"),
    dataIndex: "result",
    render: function render(text) {
      return /*#__PURE__*/React.createElement("div", null, getText("table-action-export-import-log-ok")((text === null || text === void 0 ? void 0 : text.success) || 0), text !== null && text !== void 0 && text.fail ? getText("table-action-export-import-log-err")((text === null || text === void 0 ? void 0 : text.fail) || 0) : null);
    }
  }, {
    title: getText("table-action-export-import-file-account"),
    dataIndex: "account",
    render: function render(text) {
      return text ? /*#__PURE__*/React.createElement("div", null, "".concat((text === null || text === void 0 ? void 0 : text.first_name) || "", " ").concat((text === null || text === void 0 ? void 0 : text.last_name) || "")) : null;
    }
  }, {
    title: getText("table-action-export-import-file-created"),
    dataIndex: "created_at",
    render: function render(text) {
      return formatDate(text);
    }
  }];
  var modalContent = useMemo(function () {
    var _list$2, _list$2$result, _list$2$result$fail_m;
    return /*#__PURE__*/React.createElement("div", {
      className: "export-history-content"
    }, /*#__PURE__*/React.createElement(Table, {
      rowClassName: "antd-table-row",
      columns: columns,
      dataSource: list,
      pagination: false,
      rowKey: function rowKey(record) {
        return record.id;
      },
      scroll: {
        x: true
      }
    }), /*#__PURE__*/React.createElement("div", {
      className: "error-content"
    }, /*#__PURE__*/React.createElement("div", {
      className: "header"
    }, /*#__PURE__*/React.createElement("span", null, getText("table-action-export-import-log-err-log")), /*#__PURE__*/React.createElement("a", {
      onClick: function onClick() {
        var _list$, _list$$result, _list$$result$fail_ms;
        var text = (list === null || list === void 0 ? void 0 : (_list$ = list[0]) === null || _list$ === void 0 ? void 0 : (_list$$result = _list$.result) === null || _list$$result === void 0 ? void 0 : (_list$$result$fail_ms = _list$$result.fail_msg) === null || _list$$result$fail_ms === void 0 ? void 0 : _list$$result$fail_ms.join(",")) || "";
        copyText(text);
      }
    }, getText("table-action-export-import-log-copy"))), /*#__PURE__*/React.createElement("div", {
      className: "box"
    }, list === null || list === void 0 ? void 0 : (_list$2 = list[0]) === null || _list$2 === void 0 ? void 0 : (_list$2$result = _list$2.result) === null || _list$2$result === void 0 ? void 0 : (_list$2$result$fail_m = _list$2$result.fail_msg) === null || _list$2$result$fail_m === void 0 ? void 0 : _list$2$result$fail_m.map(function (i, index) {
      return /*#__PURE__*/React.createElement("div", {
        key: index
      }, i);
    }))));
  }, [list]);
  useImperativeHandle(ref, function () {
    return {
      open: function open(params) {
        setList((params === null || params === void 0 ? void 0 : params.list) || []);
        setOpen(true);
      }
    };
  });
  return /*#__PURE__*/React.createElement(Modal, {
    open: open,
    title: getText("table-action-export-import-log-detail-title"),
    width: 900,
    footer: null,
    destroyOnClose: true,
    onCancel: function onCancel() {
      return setOpen(false);
    },
    className: "antd-modal-detail-modal"
  }, modalContent);
};
export default /*#__PURE__*/forwardRef(Detail);