from ploneintranet.layout.interfaces import IPloneintranetFormLayer
from ploneintranet.network.behaviors.metadata import IPublication
from ploneintranet.workspace.basecontent.widgets import PatDatePickerWidget
from z3c.form.interfaces import IFieldWidget
from z3c.form.util import getSpecification
from z3c.form.widget import FieldWidget
from zope.component import adapter
from zope.interface import implementer


@adapter(getSpecification(IPublication["effective"]), IPloneintranetFormLayer)
@implementer(IFieldWidget)
def EffectivePatDatePickerFieldWidget(field, request):
    return FieldWidget(field, PatDatePickerWidget(request))


@adapter(getSpecification(IPublication["expires"]), IPloneintranetFormLayer)
@implementer(IFieldWidget)
def ExpiresPatDatePickerFieldWidget(field, request):
    return FieldWidget(field, PatDatePickerWidget(request))
