from django.db import models
from django.utils.translation import gettext_lazy as _
from rr.fields import RoadRunnerField

from wagtail.admin.panels import FieldPanel
from wagtail.search import index

from ocyan.plugin.wagtail.models import AbstractBasePage


class RoadrunnerPage(AbstractBasePage):
    template = "roadrunner/roadrunner_page.html"
    content = RoadRunnerField(null=True, blank=True, use_json_field=True)
    noindex = models.BooleanField(default=False)

    content_panels = AbstractBasePage.content_panels + [
        FieldPanel("content", classname="full", disable_comments=True)
    ]

    promote_panels = AbstractBasePage.promote_panels + [FieldPanel("noindex")]

    search_fields = AbstractBasePage.search_fields + [
        index.SearchField("content", partial_match=True),
    ]

    page_description = _("Gives full control over the layout of your page.")

    class Meta:
        verbose_name = _("Pagemaker page")
        verbose_name_plural = _("Pagemaker pages")
