import { IconCode } from '@tabler/icons-react';

import ActionButton from '../components/ActionButton';
import { useTextArea } from '../context';

const Code = ({ title }: { title: string }) => {
  const { editor } = useTextArea();

  if (!editor) {
    return null;
  }

  return (
    <ActionButton
      title={title}
      icon={<IconCode />}
      onClick={() => editor.chain().focus().toggleCode().run()}
      isActive={editor.isActive('code')}
      disabled={editor.isActive('link')}
    />
  );
};

export default Code;
