"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = ExportXlsxComponent;
var _button = _interopRequireDefault(require("antd/lib/button"));
require("./index.css");
var _jsExportExcel = _interopRequireDefault(require("js-export-excel"));
/*
 * @Author: wangrongrong wangrongrong@bigo.sg
 * @Date: 2022-06-23 15:42:02
 * @LastEditors: wangrongrong wangrongrong@bigo.sg
 * @LastEditTime: 2023-03-15 11:35:46
 * @FilePath: /lowcode-material/devopsComponent/src/components/export-xlsx-component/export-xlsx-component.tsx
 * @Description: excel用户自定义数据文件下载组件
 */

function ExportXlsxComponent(props) {
  var source = props.source,
    title = props.title,
    header = props.header;
  var downloadExcel = function downloadExcel() {
    var option = {
      fileName: ''
    };
    var item;
    if (Array.isArray(source)) {
      item = source[0];
    }
    var keys = Object.keys(item);
    var values = Object.values(item);
    option.fileName = title;
    option.datas = [{
      sheetData: source,
      sheetName: 'sheet',
      sheetFilter: keys,
      sheetHeader: header || keys
    }];
    var toExcel = new _jsExportExcel["default"](option);
    toExcel.saveExcel();
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "Editor"
  }, /*#__PURE__*/React.createElement(_button["default"], {
    onClick: downloadExcel
  }, "\u5BFC\u51FAExcel"));
}