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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
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;
    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$;
        var text = (list === null || list === void 0 || (_list$ = list[0]) === null || _list$ === void 0 || (_list$ = _list$.result) === null || _list$ === void 0 || (_list$ = _list$.fail_msg) === null || _list$ === void 0 ? void 0 : _list$.join(",")) || "";
        copyText(text);
      }
    }, getText("table-action-export-import-log-copy"))), /*#__PURE__*/React.createElement("div", {
      className: "box"
    }, list === null || list === void 0 || (_list$2 = list[0]) === null || _list$2 === void 0 || (_list$2 = _list$2.result) === null || _list$2 === void 0 || (_list$2 = _list$2.fail_msg) === null || _list$2 === void 0 ? void 0 : _list$2.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);