"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = FileUploadComponent;
var _input = _interopRequireDefault(require("antd/lib/input"));
require("./index.css");
var XLSX = _interopRequireWildcard(require("xlsx"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// import * as React from 'react';

var headerMap1 = {
  "area": "地区",
  "community": "评论",
  "idc": "idc",
  "idc_community": "idc_community",
  "asn": "asn"
};
function FileUploadComponent(props) {
  var onChange = props.onChange;
  var onImportExcel = function onImportExcel(e, headerMap, handleResCallback, errorCallback) {
    if (headerMap === void 0) {
      headerMap = headerMap1;
    }
    var _e$target = e === null || e === void 0 ? void 0 : e.target,
      files = _e$target.files;
    if (!files) return;
    var file = files[0];
    var fileReader = new FileReader();
    fileReader.readAsBinaryString(file);
    fileReader.onload = function (event) {
      try {
        var result = event.target.result;
        var wb = XLSX.read(result, {
          type: 'binary'
        });
        var res = [];
        for (var sheet in wb.Sheets) {
          if (wb.Sheets.hasOwnProperty(sheet)) {
            console.log('sheet==', sheet);
            var data = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
            console.log('data===', data);
            res = res.concat(data);
          }
        }
        onChange(res);
      } catch (e) {
        console.log('error==', e);
      }
    };
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "Editor"
  }, /*#__PURE__*/React.createElement(_input["default"], {
    id: "upfile",
    type: "file",
    accept: ".xlsx",
    onChange: onImportExcel
  }));
}

// export default class EditorComponent extends React.Component<any, EditorComponentProps, void> {
//   width: any;
//   height: any;
//   language: any;
//   theme: string;
//   constructor(props) {
//     super(props);
//     this.width = props.width || '100%';
//     this.height = props.height || '500';
//     this.language = props.language || 'powershell';
//     this.theme = 'vs-dark';
//     // const { width = '100%', height = '500', language = 'powershell', theme = 'vs-dark', ...others } = props;
//   }
//   render() {
//     return (
//         <MonacoEditor 
//           width={this.width}
//           height={this.height}
//           language={this.language}
//           theme={this.theme}
//         // {...others}
//       />
//     )
//   }
// }