# -*- coding: utf-8 -*-
from __future__ import annotations

from crispy_forms.layout import Submit
from django import forms
from django.utils.translation import gettext_lazy as _

from .base import ConfirmationMixin, Form


class AssociationForm(Form):
    pass


class ConfirmationForm(ConfirmationMixin, AssociationForm):
    title = forms.CharField(
        label=_('Title'),
        required=False,
        disabled=True,
        show_hidden_initial=True,
    )
    url = forms.CharField(
        label=_('URL'),
        required=False,
        disabled=True,
        show_hidden_initial=True,
    )

    def get_layout_fields(self) -> list[str]:
        return [
            'canhazconfirm',
            'title',
            'url',
        ]

    def get_submit_button(self) -> Submit:
        return Submit('submit', _('Confirm'), css_class='btn btn-primary')


class EditForm(AssociationForm):
    url = forms.CharField(
        label=_('URL'),
        required=False,
        disabled=True,
        show_hidden_initial=True,
    )
    target_title = forms.CharField(
        label=_('Title'),
        required=False,
    )
    target_description = forms.CharField(
        label=_('Description'),
        required=False,
        widget=forms.Textarea,
    )

    def get_layout_fields(self) -> list[str]:
        return [
            'url',
            'target_title',
            'target_description',
        ]

    def clean(self):
        cleaned_data = super().clean()

        result = {}

        if cleaned_data['target_title']:
            result['target_title'] = cleaned_data['target_title']

        if cleaned_data['target_description']:
            result['target_description'] = cleaned_data['target_description']

        return result


class RefreshForm(ConfirmationForm):
    def get_submit_button(self) -> Submit:
        return Submit('submit', _('Refresh'), css_class='btn btn-warning')


class ArchiveForm(ConfirmationForm):
    def get_submit_button(self) -> Submit:
        return Submit('submit', _('Archive'), css_class='btn btn-danger')


class DeleteForm(ConfirmationForm):
    def get_submit_button(self) -> Submit:
        return Submit('submit', _('Delete'), css_class='btn btn-danger')
