# This file is part of Gajim.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from base64 import b64decode
from unittest.mock import MagicMock

from nbxmpp.modules.dataforms import extend_form
from nbxmpp.simplexml import Node

from gajim.common import app

from gajim.gtk.dataform import DataFormWidget
from gajim.gtk.window import GajimAppWindow

from . import util

image = """iVBORw0KGgoAAAANSUhEUgAAAIwAAAA8CAAAAACRYQ2XAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfiCwQXMiypK
[encoded data, 4824 characters]
TEtMDRUMjM6NTA6NDQrMDE6MDBAxMf7AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE4LTExLTA0VDIzOjUwOjQ0KzAxOjAwMZl/RwAAAABJRU5ErkJggg=="""  # noqa: E501


FORM = """
<x xmlns='jabber:x:data' type='form'>
  <title>Bot Configuration</title>
  <instructions>Fill out this form to configure your new bot!</instructions>
  <field type='hidden'
         var='FORM_TYPE'>
    <value>jabber:bot</value>
  </field>
  <field type='fixed'><value>Section 1: Bot Info</value></field>
  <field type='text-single'
         label='The name of your bot'
         var='botname'>
    <required/>
  </field>
  <field type='text-multi'
         label='Helpful description of your bot'
         var='description'>
    <required/>
  </field>
  <field type='boolean'
         label='Public bot?'
         var='public'/>
  <field type='text-private'
         label='Password for special access'
         var='password'>
    <required/>
  </field>
  <field type='fixed'><value>Section 2: Features</value></field>
  <field type='list-multi'
         label='What features will the bot support?'
         var='features'>
    <option label='Contests'><value>contests</value></option>
    <option label='News'><value>news</value></option>
    <option label='Polls'><value>polls</value></option>
    <option label='Reminders'><value>reminders</value></option>
    <option label='Search'><value>search</value></option>
    <option label='Search1'><value>search1</value></option>
    <option label='Really long long long long long long long long entry'><value>longentry</value></option>
    <option label='Search3'><value>search3</value></option>
    <value>news</value>
    <value>search</value>
  </field>
  <field type='fixed'><value>Section 3: Subscriber List</value></field>
  <field type='list-single'
         label='Maximum number of subscribers'
         var='maxsubs'>
    <value>20</value>
    <option label='10'><value>10</value></option>
    <option label='20'><value>20</value></option>
    <option label='30'><value>30</value></option>
    <option label='50'><value>50</value></option>
    <option label='100'><value>100</value></option>
    <option label='None'><value>none</value></option>
  </field>
  <field type='fixed'><value>Section 4: Invitations</value></field>
  <field type='jid-multi'
         label='People to invite'
         var='invitelist'>
    <desc>Tell all your friends about your new bot!</desc>
    <required/>
    <value>juliet@capulet.com</value>
    <value>benvolio@montague.net</value>
  </field>
  <field var='ocr' type='text-single' label='Fill in what you see'>
    <media xmlns='urn:xmpp:media-element'>
      <uri type='image/png'>cid:sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org</uri>
    </media>
    <required/>
  </field>
</x>
"""  # noqa: E501


class TestDataFormWindow(GajimAppWindow):
    def __init__(self):
        GajimAppWindow.__init__(
            self,
            name="",
            title=__class__.__name__,
            default_width=1000,
            default_height=600,
            add_window_padding=True,
            header_bar=True,
        )
        options = {
            "left-width": 100,
            "form-width": 435,
        }
        self._widget = DataFormWidget(extend_form(node=Node(node=FORM)), options)
        self.set_child(self._widget)

    def _cleanup(self) -> None:
        pass


app.bob_cache["sha1+8f35fef110ffc5df08d579a50083ff9308fb6242"] = b64decode(image)  # noqa: E501
app.css_config = MagicMock()
app.css_config.get_value = MagicMock(return_value="rgb(100, 100, 255)")

util.init_settings()

window = TestDataFormWindow()
window.show()

util.run_app()
