from django import forms
from django.utils.functional import cached_property
from django.utils.translation import gettext as _

from wagtail.admin.staticfiles import versioned_static
from wagtail.blocks.field_block import FieldBlockAdapter


class PreviewAdminChooserAdapter(FieldBlockAdapter):
    js_constructor = "ocyan.PreviewAdminChooser"

    def js_args(self, block):
        name, values, meta = super().js_args(block)
        meta["strings"]["EMPTY"] = _("No choice has been made")
        return name, values, meta

    @cached_property
    def media(self):
        return super().media + forms.Media(
            js=[
                versioned_static("wagtailadmin/js/telepath/blocks.js"),
                versioned_static("roadrunner/roadrunner.js"),
                versioned_static("wagtailadmin/js/roadrunner_bs5.js"),
            ],
        )


class PreviewSelectAdapter(PreviewAdminChooserAdapter):
    js_constructor = "ocyan.PreviewSelect"
