import {
  insertNodes,
  PlateEditor,
  Value,
  withoutNormalizing,
} from '@udecode/plate-common';

import { ELEMENT_STATUS } from './createStatusPlugin';
import { TStatusElement } from './status-store';

export const insertStatus = <V extends Value>(
  editor: PlateEditor<V>,
  category: TStatusElement['category'] = 'gray'
) => {
  withoutNormalizing(editor, () => {
    insertNodes<TStatusElement>(editor, {
      type: ELEMENT_STATUS,
      category: category,
      value: category === 'time' ? '时间' : '状态',
      children: [{ text: '' }],
    });
  });
};
