import { PluginKey } from '@atlaskit/editor-prosemirror/state';
import { SafePlugin } from '../../../safe-plugin';
export const appearancePluginKey = new PluginKey('appearancePlugin');
const DEFAULT_APPEARANCE = 'comment';

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