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, createContext } from "react";
import ImageIcon from "@material-ui/icons/Image";
import OndemandVideoIcon from "@material-ui/icons/OndemandVideo";
import TransformVideoKeyframesDialog from "../TransformVideoKeyframesDialog";
import DownloadURLsDialog from "../DownloadURLsDialog";
import GetAppIcon from "@material-ui/icons/GetApp";
import CollectionsIcon from "@material-ui/icons/Collections";
import TransformVideoFramesToImagesDialog from "../TransformVideoFramesToImagesDialog";
import TransformLocalFilesToWebURLs from "../TransformLocalFilesToWebURLs";
import TransformImageSamplesIntoSegmentsDialog from "../TransformImageSamplesIntoSegmentsDialog";
import TransformSegmentsIntoImageSamplesDialog from "../TransformSegmentsIntoImageSamplesDialog";
import TransformRemoveInvalidSamplesDialog from "../TransformRemoveInvalidSamplesDialog";
import { usePlugins } from "../PluginProvider";
import PluginDialog from "../PluginDialog";
import useInterface from "../../hooks/use-interface";
import useActiveDatasetManager from "../../hooks/use-active-dataset-manager";
import Button from "./Button";
import PeopleAltIcon from "@material-ui/icons/PeopleAlt";
import ComputerIcon from "@material-ui/icons/Computer";
import HighlightOffIcon from "@material-ui/icons/HighlightOff";
import LanguageIcon from "@material-ui/icons/Language";
import CheckBoxOutlineBlankIcon from "@material-ui/icons/CheckBoxOutlineBlank";
import GridOnIcon from "@material-ui/icons/GridOn";
import { useTranslation } from "react-i18next";
export var SelectDialogContext = createContext();
export default (function () {
  var _useTranslation = useTranslation(),
      t = _useTranslation.t;

  var _useState = useState(),
      _useState2 = _slicedToArray(_useState, 2),
      selectedDialog = _useState2[0],
      changeDialog = _useState2[1];

  var _useInterface = useInterface(),
      iface = _useInterface.iface;

  var onChangeDialog = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(dialog) {
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.t0 = dialog;
              _context.next = _context.t0 === "convert-keyframes-to-samples" ? 3 : 4;
              break;

            case 3:
              return _context.abrupt("break", 5);

            case 4:
              return _context.abrupt("return", changeDialog(dialog));

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

    return function onChangeDialog(_x) {
      return _ref.apply(this, arguments);
    };
  }();

  var closeDialog = function closeDialog() {
    return changeDialog(null);
  };

  var _useState3 = useState(null),
      _useState4 = _slicedToArray(_useState3, 2),
      openPlugin = _useState4[0],
      setOpenPlugin = _useState4[1];

  var plugins = usePlugins();

  var _useActiveDatasetMana = useActiveDatasetManager(),
      _useActiveDatasetMana2 = _slicedToArray(_useActiveDatasetMana, 1),
      datasetManager = _useActiveDatasetMana2[0];

  return /*#__PURE__*/React.createElement(SelectDialogContext.Provider, {
    value: {
      onChangeDialog: onChangeDialog
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
    disabled: (iface === null || iface === void 0 ? void 0 : iface.type) !== "video_segmentation",
    dialog: "convert-keyframes-to-samples",
    Icon1: OndemandVideoIcon,
    Icon2: CollectionsIcon
  }, t("convert-video-keyframes-to-samples")), /*#__PURE__*/React.createElement(Button, {
    desktopOnly: true,
    dialog: "convert-local-files-to-web-urls",
    Icon1: ComputerIcon,
    Icon2: LanguageIcon
  }, t("transform-local-files-to-web-urls")), /*#__PURE__*/React.createElement(Button, {
    desktopOnly: true,
    dialog: "download-urls",
    Icon1: GetAppIcon
  }, t("download"), " URLs"), /*#__PURE__*/React.createElement(Button, {
    desktopOnly: true,
    dialog: "convert-video-frames-to-images",
    Icon1: OndemandVideoIcon,
    Icon2: ImageIcon
  }, t("convert-video-frames-to-images")), /*#__PURE__*/React.createElement(Button, {
    dialog: "split-image-samples-into-segments",
    Icon1: CheckBoxOutlineBlankIcon,
    Icon2: GridOnIcon
  }, "Split Image Samples into Segments"), /*#__PURE__*/React.createElement(Button, {
    dialog: "combine-segments-into-image-samples",
    Icon1: GridOnIcon,
    Icon2: CheckBoxOutlineBlankIcon
  }, "Combine Segments into Image Samples"), /*#__PURE__*/React.createElement(Button, {
    dialog: "remove-invalid-samples",
    Icon1: ImageIcon,
    Icon2: HighlightOffIcon
  }, "Remove Invalid Samples"), plugins.map(function (plugin) {
    return /*#__PURE__*/React.createElement(Button, {
      key: plugin.name,
      Icon1: PeopleAltIcon,
      Icon2: PeopleAltIcon,
      onClick: function onClick() {
        return setOpenPlugin(plugin);
      }
    }, plugin.name);
  }), openPlugin && /*#__PURE__*/React.createElement(PluginDialog, Object.assign({
    open: Boolean(openPlugin),
    onClose: function onClose() {
      return setOpenPlugin(null);
    }
  }, openPlugin, {
    datasetManager: datasetManager
  })), /*#__PURE__*/React.createElement(TransformRemoveInvalidSamplesDialog, {
    open: selectedDialog === "remove-invalid-samples",
    onClose: closeDialog
  }), /*#__PURE__*/React.createElement(TransformVideoKeyframesDialog, {
    open: selectedDialog === "convert-keyframes-to-samples",
    onClose: closeDialog
  }), /*#__PURE__*/React.createElement(DownloadURLsDialog, {
    open: selectedDialog === "download-urls",
    onClose: closeDialog,
    desktopOnly: true
  }), /*#__PURE__*/React.createElement(TransformLocalFilesToWebURLs, {
    onClose: closeDialog,
    desktopOnly: true,
    open: selectedDialog === "convert-local-files-to-web-urls"
  }), /*#__PURE__*/React.createElement(TransformVideoFramesToImagesDialog, {
    open: selectedDialog === "convert-video-frames-to-images",
    onClose: closeDialog,
    desktopOnly: true
  }), /*#__PURE__*/React.createElement(TransformImageSamplesIntoSegmentsDialog, {
    open: selectedDialog === "split-image-samples-into-segments",
    onClose: closeDialog
  }), /*#__PURE__*/React.createElement(TransformSegmentsIntoImageSamplesDialog, {
    open: selectedDialog === "combine-segments-into-image-samples",
    onClose: closeDialog
  })));
});