from grapple.models import GraphQLRichText, GraphQLStreamfield
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page
from wagtail.search import index

from dnscms.blocks import PageSectionBlock
from dnscms.fields import BASE_BLOCKS


class GenericPage(Page):
    subpage_types = ["generic.GenericPage"]
    show_in_menus = True

    lead = RichTextField(features=["bold", "italic", "link"])
    body = StreamField(BASE_BLOCKS + [("page_section", PageSectionBlock())])

    content_panels = Page.content_panels + [
        FieldPanel("lead", heading="Ingress"),
        FieldPanel("body", heading="Innhold"),
    ]

    graphql_fields = [
        GraphQLRichText("lead"),
        GraphQLStreamfield("body"),
    ]

    search_fields = Page.search_fields + [index.SearchField("lead"), index.SearchField("body")]
