from django import forms
from django.db import models

from .widgets import LexicalEditorWidget


class RichTextField(models.TextField):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        defaults = {"form_class": RichTextFormField}
        defaults.update(kwargs)
        return super().formfield(**defaults)


class RichTextFormField(forms.CharField):
    widget = LexicalEditorWidget

    def __init__(self, *args, **kwargs):
        kwargs["widget"] = self.widget()
        super().__init__(*args, **kwargs)
