import * as React from "react";
import { getPlugins } from "../../../../plugins";
import { ELEMENT_CREATED, activateElement, togglePlugin } from "../../../actions";
import { ReactComponent as SettingsIcon } from "@svgr/webpack!../../../assets/icons/settings.svg";
import AdvancedSettings from "./AdvancedSettings";
import Action from "../components/Action";
import AdvancedAction from "./AdvancedAction";
export default [{
  name: "pb-editor-content-element-advanced-settings",
  type: "pb-editor-content",
  render: function render() {
    return /*#__PURE__*/React.createElement(AdvancedSettings, null);
  }
}, {
  type: "pb-editor-redux-middleware",
  name: "pb-editor-redux-middleware-advanced-settings",
  actions: [ELEMENT_CREATED],
  middleware: function middleware(_ref) {
    var store = _ref.store,
        action = _ref.action,
        next = _ref.next;
    var _action$payload = action.payload,
        element = _action$payload.element,
        source = _action$payload.source;
    next(action); // Check the source of the element (could be `saved` element which behaves differently from other elements)

    var sourcePlugin = getPlugins("pb-editor-page-element").find(function (pl) {
      return pl.elementType === source.type;
    });

    if (!sourcePlugin) {
      return;
    }

    var onCreate = sourcePlugin.onCreate;

    if (!onCreate || onCreate !== "skip") {
      // If source element does not define a specific `onCreate` behavior - continue with the actual element plugin
      var plugin = getPlugins("pb-editor-page-element").find(function (pl) {
        return pl.elementType === element.type;
      });

      if (!plugin) {
        return;
      }

      var _onCreate = plugin.onCreate;

      if (_onCreate && _onCreate === "open-settings") {
        store.dispatch(activateElement({
          element: element.id
        }));
        store.dispatch(togglePlugin({
          name: "pb-editor-page-element-settings-advanced"
        }));
      }
    }
  }
}, {
  name: "pb-editor-page-element-settings-advanced",
  type: "pb-editor-page-element-settings",
  renderAction: function renderAction() {
    return /*#__PURE__*/React.createElement(AdvancedAction, null, /*#__PURE__*/React.createElement(Action, {
      plugin: this.name,
      icon: /*#__PURE__*/React.createElement(SettingsIcon, null),
      "data-testid": "pb-editor-advanced-settings-button",
      tooltip: "Advanced settings"
    }));
  }
}];
//# sourceMappingURL=index.js.map