"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.appearancePluginKey = void 0;
exports.createAppearancePlugin = createAppearancePlugin;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _state = require("@atlaskit/editor-prosemirror/state");
var _safePlugin = require("../../../safe-plugin");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var appearancePluginKey = exports.appearancePluginKey = new _state.PluginKey('appearancePlugin');
var DEFAULT_APPEARANCE = 'comment';

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function createAppearancePlugin(initialAppearance) {
  return new _safePlugin.SafePlugin({
    key: appearancePluginKey,
    state: {
      init: function init() {
        return {
          appearance: initialAppearance !== null && initialAppearance !== void 0 ? initialAppearance : DEFAULT_APPEARANCE
        };
      },
      apply: function apply(tr, pluginState) {
        var meta = tr.getMeta(appearancePluginKey);
        if ((meta === null || meta === void 0 ? void 0 : meta.appearance) !== undefined) {
          return _objectSpread(_objectSpread({}, pluginState), {}, {
            appearance: meta.appearance
          });
        }
        return pluginState;
      }
    }
  });
}