import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import React, { useState, useEffect } from "react";
import SimpleDialog from "../SimpleDialog";
import TextAreaWithUpload from "../TextAreaWithUpload";
import { useAppConfig } from "../AppConfig";
export var ManagePluginsDialog = function ManagePluginsDialog(_ref) {
  var onClose = _ref.onClose,
      open = _ref.open;

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

  var _useState = useState(),
      _useState2 = _slicedToArray(_useState, 2),
      content = _useState2[0],
      setContent = _useState2[1];

  useEffect(function () {
    if (!open) return;
    setContent(fromConfig("pluginUrls") || ""); //eslint-disable-next-line
  }, [open]);
  return /*#__PURE__*/React.createElement(SimpleDialog, {
    title: "Manage Plugins",
    onClose: onClose,
    open: open,
    actions: [{
      text: "Save Plugins",
      onClick: function onClick() {
        setInConfig("pluginUrls", content.trim().split("\n").map(function (line) {
          return line.trim();
        }).filter(Boolean).join("\n"));
        onClose();
      }
    }]
  }, /*#__PURE__*/React.createElement(TextAreaWithUpload, {
    content: content,
    onChangeContent: setContent,
    placeholder: "Write the URLs to each plugin here, one plugin url per line.\n\ne.g.\nhttps://unpkg.com/udt-transform-delete-samples@1.0.4/plugin-config.js\n\nYou can also upload a text file with the urls."
  }));
};
export default ManagePluginsDialog;