import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import React from "react";
import SimpleDialog from "../SimpleDialog";
import { styled } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableContainer from "@material-ui/core/TableContainer";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import { useTranslation } from "react-i18next";
var datasets = [{
  name: "Elon Musk Tweets",
  type: "text",
  size: 2800
}, {
  name: "Cats",
  type: "image",
  size: 360
}, {
  name: "VR Hand Pinching",
  type: "image",
  size: 20517
}, {
  name: "AI Generated Faces",
  type: "image",
  size: 1999
}, {
  name: "Text to Speech Audio",
  type: "audio",
  size: 200
}];

function getSamples(_x) {
  return _getSamples.apply(this, arguments);
}

function _getSamples() {
  _getSamples = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(dataset) {
    var datasetName, datasetUrl;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            datasetName = dataset.name.toLowerCase().replace(/ /g, "_") + ".udt.json";
            datasetUrl = "https://s3.amazonaws.com/datasets.workaround.online/".concat(datasetName);
            _context2.next = 4;
            return fetch(datasetUrl).then(function (r) {
              return r.json();
            }).then(function (r) {
              return r.samples || r.taskData;
            });

          case 4:
            return _context2.abrupt("return", _context2.sent);

          case 5:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _getSamples.apply(this, arguments);
}

var StyledButton = styled(Button)({});

var ImportToyDatasetDialog = function ImportToyDatasetDialog(_ref) {
  var onClose = _ref.onClose,
      onAddSamples = _ref.onAddSamples,
      open = _ref.open;

  var _useTranslation = useTranslation(),
      t = _useTranslation.t;

  return /*#__PURE__*/React.createElement(SimpleDialog, {
    onClose: onClose,
    open: open,
    title: "Import Toy Dataset"
  }, /*#__PURE__*/React.createElement(TableContainer, null, /*#__PURE__*/React.createElement(Table, null, /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableCell, null, t("name")), /*#__PURE__*/React.createElement(TableCell, null, t("type")), /*#__PURE__*/React.createElement(TableCell, null, t("size")), /*#__PURE__*/React.createElement(TableCell, null, t("actions")))), /*#__PURE__*/React.createElement(TableBody, null, datasets.map(function (dataset) {
    return /*#__PURE__*/React.createElement(TableRow, {
      key: dataset.name
    }, /*#__PURE__*/React.createElement(TableCell, null, dataset.name), /*#__PURE__*/React.createElement(TableCell, null, dataset.type), /*#__PURE__*/React.createElement(TableCell, null, dataset.size), /*#__PURE__*/React.createElement(TableCell, null, /*#__PURE__*/React.createElement(StyledButton, {
      "data-import-toy-dataset-name": dataset.name,
      onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.t0 = onAddSamples;
                _context.next = 3;
                return getSamples(dataset);

              case 3:
                _context.t1 = _context.sent;
                (0, _context.t0)(_context.t1);

              case 5:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      })),
      variant: "outlined"
    }, t("import"))));
  })))));
};

export default ImportToyDatasetDialog;