import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import React, { useState } from "react";
import SimpleDialog from "../SimpleDialog";
import transformFileURLsToWebURLs from "./functions/transform-file-urls-to-web-urls";
import ProgressBar from "../ProgressBar";
import useElectron from "../../hooks/use-electron";
import { useTranslation } from "react-i18next";

var TransformLocalFilesToWebURLs = function TransformLocalFilesToWebURLs(_ref) {
  var open = _ref.open,
      onClose = _ref.onClose,
      dataset = _ref.dataset,
      onChangeDataset = _ref.onChangeDataset;

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

  var _useState = useState(0),
      _useState2 = _slicedToArray(_useState, 2),
      progress = _useState2[0],
      setProgress = _useState2[1];

  var _ref2 = useElectron() || {},
      remote = _ref2.remote;

  return /*#__PURE__*/React.createElement(SimpleDialog, {
    open: open,
    onClose: onClose,
    title: "Convert Local Files to Web URLs",
    actions: [{
      text: "Convert Local Files to Web URLs",
      onClick: function () {
        var _onClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
          return _regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  _context.next = 2;
                  return transformFileURLsToWebURLs({
                    dataset: dataset,
                    onChangeDataset: onChangeDataset,
                    setProgress: setProgress,
                    remote: remote
                  });

                case 2:
                  return _context.abrupt("return", _context.sent);

                case 3:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee);
        }));

        function onClick() {
          return _onClick.apply(this, arguments);
        }

        return onClick;
      }()
    }]
  }, t("transform-local-files-to-web-urls-explanation"), /*#__PURE__*/React.createElement(ProgressBar, {
    progress: progress
  }));
};

export default TransformLocalFilesToWebURLs;