from django import forms
from django.utils.functional import cached_property

from wagtail.admin.telepath.widgets import WidgetAdapter
from wagtail.admin.staticfiles import versioned_static
from wagtail.admin.widgets.chooser import PageChooserAdapter


class CoyoteAdapterMediaMixin:
    @cached_property
    def media(self):
        return super().media + forms.Media(
            js=[
                versioned_static("wagtailadmin/js/telepath/blocks.js"),
                versioned_static("wagtailadmin/js/page-chooser-modal.js"),
                versioned_static("wagtailadmin/js/page-chooser-telepath.js"),
                versioned_static("wagtailadmin/coyote/coyote.js"),
            ],
            css={
                "all": [
                    versioned_static("css/external.css"),
                    versioned_static("wagtailadmin/coyote/coyote.css"),
                ]
            },
        )


class VisualChoiceAdapter(CoyoteAdapterMediaMixin, WidgetAdapter):
    js_constructor = "coyote.widgets.VisualChoice"


class ColorChoiceAdapter(CoyoteAdapterMediaMixin, WidgetAdapter):
    js_constructor = "coyote.widgets.ColorChoice"


class IconChoiceAdapter(CoyoteAdapterMediaMixin, WidgetAdapter):
    js_constructor = "coyote.widgets.IconChoice"


class AdminLinkChooserAdapter(CoyoteAdapterMediaMixin, PageChooserAdapter):
    js_constructor = "coyote.widgets.AdminLinkChooser"
