from wagtail import blocks


class MediaLibraryContentBlock(blocks.StructBlock):
    title = blocks.TextBlock()
    description = blocks.TextBlock(default="", required=False)
    icon_url = blocks.TextBlock(default="", required=False)
    link_display_text = blocks.CharBlock(max_length=255, default="Link öffnen")
    url = blocks.TextBlock(default="", required=False)
    open_window = blocks.BooleanBlock(default=False)
    # page = blocks.PageChooserBlock(
    #     page_type=["learnpath.LearningContent"], required=False
    # )


class ExternalLinkBlock(MediaLibraryContentBlock):
    pass


class InternalLinkBlock(MediaLibraryContentBlock):
    pass


class RelativeLinkBlock(MediaLibraryContentBlock):
    pass


class LearnMediaBlock(MediaLibraryContentBlock):
    pass


class MediaContentCollection(blocks.StructBlock):
    """
    Lernmedien, Links, Querverweise, Verankerung
    """

    title = blocks.TextBlock()
    description = blocks.TextBlock(default="", required=False)
    contents = blocks.StreamBlock(
        [
            ("learn_media", MediaLibraryContentBlock()),
            ("external_link", ExternalLinkBlock()),
            ("internal_link", InternalLinkBlock()),
            ("relative_link", RelativeLinkBlock()),
        ]
    )

    class Meta:
        icon = "link"
