import type { BlockDefinition } from '../../types';

const horizontalRule: BlockDefinition = {
  label: '水平罫線',
  icon: 'horizontal_rule',
  description: '水平罫線',
  isTextMenu: false,
  aliases: ['hr', 'rule', 'separator'],
  createActions: (cmd, ctx) => ({
    action: (editor) => {
      ctx.recordUsage(cmd);
      const { $from } = editor.state.selection;
      const pos = $from.before($from.depth);
      editor.chain().focus().setHorizontalRule().run();
      editor.chain().focus().setBlockAttrs(pos, { class: cmd.class }).run();
    },
    convert: () => {},
    isDisabled: () => true,
    isActive: (editor) => editor.isActive('horizontalRule'),
  }),
};

export default horizontalRule;
