import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import React, { useState } from "react";
import Box from "@material-ui/core/Box";
import MuiButton from "@material-ui/core/Button";
import { useUpdate } from "react-use";
import { styled } from "@material-ui/core/styles";
import usePosthog from "../../hooks/use-posthog";
import { useAppConfig } from "../AppConfig";
import { useHotkeyStorage } from "../HotkeyStorage";
import KeyboardShortcutManagerDialog from "../KeyboardShortcutManagerDialog";
import { useTranslation } from "react-i18next";
var Button = styled(MuiButton)({
  margin: 8
});
export var AdvancedOptionsView = function AdvancedOptionsView(_ref) {
  var onClickEditJSON = _ref.onClickEditJSON,
      onClearLabelData = _ref.onClearLabelData;
  var forceUpdate = useUpdate();
  var posthog = usePosthog();

  var _useAppConfig = useAppConfig(),
      fromConfig = _useAppConfig.fromConfig,
      setInConfig = _useAppConfig.setInConfig;

  var _useHotkeyStorage = useHotkeyStorage(),
      hotkeys = _useHotkeyStorage.hotkeys,
      changeHotkey = _useHotkeyStorage.changeHotkey,
      clearHotkeys = _useHotkeyStorage.clearHotkeys;

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      hotkeyDialogOpen = _useState2[0],
      setHotkeyDialogOpen = _useState2[1]; // internalization hook


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

  return /*#__PURE__*/React.createElement(Box, {
    padding: 2
  }, /*#__PURE__*/React.createElement(Button, {
    onClick: function onClick() {
      if (window.confirm("Are you sure you want to delete all your label data? Click OK to delete.")) {
        onClearLabelData();
      }
    },
    variant: "outlined"
  }, t("clear-labels")), /*#__PURE__*/React.createElement(Button, {
    variant: "outlined",
    onClick: function onClick() {
      if (posthog.has_opted_out_capturing()) {
        posthog.opt_in_capturing();
      } else {
        posthog.opt_out_capturing();
      }

      forceUpdate();
    }
  }, posthog.has_opted_out_capturing() ? "Enable" : "Disable", " ", t("telemetry")), /*#__PURE__*/React.createElement(Button, {
    variant: "outlined",
    onClick: function onClick() {
      // TODO store in appConfig
      var response = window.prompt("Input URL for new collaboration server (empty to use universaldatatool.com):", fromConfig("collaborationServer.url"));
      if (response === null) return;
      setInConfig("collaborationServer.url", response);
    }
  }, t("custom-collaboration-server")), /*#__PURE__*/React.createElement(Button, {
    variant: "outlined",
    onClick: function onClick() {
      setInConfig("labelhelp.disabled", !Boolean(fromConfig("labelhelp.disabled")));
    }
  }, fromConfig("labelhelp.disabled") ? "Enable" : "Disable", " ", t("label-help")), !fromConfig("labelhelp.disabled") && /*#__PURE__*/React.createElement(Button, {
    variant: "outlined",
    disabled: Boolean(fromConfig("labelhelp.disabled")),
    onClick: function onClick() {
      var response = window.prompt("Label Help API Key:", fromConfig("labelhelp.apikey") || "");
      if (response === null) return;
      setInConfig("labelhelp.apikey", response);
    }
  }, t("label-help-api-key")), /*#__PURE__*/React.createElement(Button, {
    variant: "outlined",
    onClick: function onClick() {
      setHotkeyDialogOpen(true);
    }
  }, "Change/View Hotkeys"), /*#__PURE__*/React.createElement(KeyboardShortcutManagerDialog, {
    open: hotkeyDialogOpen,
    hotkeyList: hotkeys,
    onClose: function onClose() {
      return setHotkeyDialogOpen(false);
    },
    onClearHotkeys: clearHotkeys,
    onChangeHotkey: function onChangeHotkey(hotkey, newBinding) {
      return changeHotkey(hotkey.id, newBinding);
    }
  }));
};
export default AdvancedOptionsView;